The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
hmm, syntax help needed...
Discuss hmm, syntax help needed... in the PHP Development forum on Dev Shed. hmm, syntax help needed... PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 5th, 2000, 03:22 PM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 15
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
I need some help with the syntax here..
I want it to do alil validation before the insert, but a query find that username is unique first.
<?php
mysql_connect (localhost, u , p);
mysql_select_db (db);
$result1 = mysql_query ("SELECT * FROM members WHERE username = '$username'");
if ($row = mysql_fetch_array($result1))
{
print ("Error: The user name ");
print ("$USER_NAME");
print (" has been taken. Go back and enter a new user name.");
print ("<p>");
$verify = "bad";
}
elseif (eregi("[a-z]{2,16}", $firstname)
| | eregi("[a-z]{2,25}", $lastname)
| | eregi("[0-9a-z]{2,50}", $st1)
| | eregi("[a-z]{2,25}", $city)
| | eregi("[a-z]{2}", $st)
| | eregi("[0-9]{5}", $zip)
| | eregi("[0-9a-z]{6,16}", $username)
| | eregi("[0-9a-z]{6,10}", $password))
| | eregi("([_.0-9a-z-]+@)([0-9a-z][0-9a-z-]+.)+([a-z]{2,3})",$email)
{
mysql_query INSERT INTO members VALUES ('$firstname',
'$lastname', '$st1', '$city', '$state', '$zip', '$username',
'$password', '$email');
print mysql_error();
}else{
print 'failed';
}
?>
Thanx
Uga
|

May 6th, 2000, 01:24 AM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
You can try the following :
$result=mysql_query ("SELECT * FROM members WHERE username = '$username'");
if (mysql_num_rows[$result]==1){
print "Username has been taken already";
}else{
$insertresult=mysql_query ("INSERT INTO members(firstname,
lastname,st1,city,state,zip,username,password,email)VALUES ('$firstname','$lastname', '$st1', '$city', '$state', '$zip', '$username',
'$password', '$email')");
if (mysql_affected_rows($insertresult) == 1){
print "Record has been addedn";
}else{
print "Error while inserting record";
exit;
}
}
------------------
SR -
shiju.dreamcenter.net
[This message has been edited by Shiju Rajan (edited May 06, 2000).]
|

May 6th, 2000, 07:40 AM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 15
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Thank you so much for a response, but will this also do the character validation that eregi would ?
Thanx,
Uga
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|