Current location: Hot Scripts Forums » Programming Languages » PHP » Data Validation form MySQL using PHP


Data Validation form MySQL using PHP

Reply
  #1 (permalink)  
Old 07-17-10, 11:55 AM
jigarlives jigarlives is offline
New Member
 
Join Date: Jul 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Data Validation form MySQL using PHP

Friends,

I have a website with Registration forms created in Php. I want that PHP checks the MySQL db for the FirstName and LastName then lets user know if the name already exists so that user can select different name.

I am using select statement but not able to compare the strings... Please can someone help me with the code to match a form value to a database value....

Also is there some way where one can print the FirstName and LastName on screen from the database.

Thanks.....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-21-10, 05:03 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,073
Thanks: 11
Thanked 88 Times in 83 Posts
I'm not sure what exactly you're doing, and it might be an unlikely event, but two (or more) people can actually have the same name plus last name.

So if I was to sign up on your site, and there's another user who shares the same name, would I be forced to "make up" another name?

Sounds kinda awkward, but if that's what you want.

PHP Code:



$firstname 
trim( (string) $_POST['FirstName'] );
$lastname trim( (string) $_POST['LastName'] );

$query mysql_query(sprintf("
    SELECT `FirstName`, `LastName`
    FROM `users`
    WHERE `FirstName` = '%s' AND `LastName`  = '%s'
    LIMIT 1"
,
    
mysql_real_escape_string($firstname),
    
mysql_real_escape_string($lastname)
) OR die(
mysql_error());

if (
$user mysql_fetch_assoc($query))
{
    
// User with this name exists
}
else
{
    
// NO user found with this name

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-22-10, 05:58 AM
mysamsung mysamsung is offline
Newbie Coder
 
Join Date: Apr 2010
Posts: 22
Thanks: 36
Thanked 0 Times in 0 Posts
yes i got it right
__________________
PHP

Last edited by mysamsung; 07-22-10 at 06:01 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks

Tags
data validation, mysql, php


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP or PHP which is better? nepala The Lounge 9 07-14-10 06:48 AM
Is there a PHP script for Online form fields into MySQL database? successforu17 Script Requests 0 03-03-10 07:44 AM
Upload images via form and insert data into MySQL database mike_jandreau PHP 7 04-06-09 07:05 PM
Write Mysql data to xml via php ragrim Script Requests 0 03-04-09 10:51 PM
Update of data using PHP truncates text data jej1216 PHP 8 09-10-08 09:52 AM


All times are GMT -5. The time now is 10:44 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.