|
-
Aug 13th, 2004, 06:34 PM
#1
Thread Starter
Frenzied Member
I want to add a error code to this
I want to add a code to this which will the make sure the user has added in a first name in the box and if not kick them out... i've tried serveral but none have worked... any ideas
PHP Code:
<?php
$check = "select id from members where username = '".$_POST['username']."';";
$qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "Sorry, the username $username is already taken. Please go back and try another.<br>";
} else {
$result = mysql_query("insert into members (`id`,`username`,`firstname`,`lastname`,`dob`,`address`,`city`,`country`,`phone`,`email`,`password`,`nz_mailing`,`active`,`warriors_mailing`,`bcc_mailing`,`level`) values ('', '".$_POST['username']."','$firstname','$lastname','$dob','$address','$city','$country','$phone','$email','".$_POST['password']."','$nz_mailing','$active','$warriors_mailing','$bcc_mailing','$level')")
or die("Could not insert data because ".mysql_error());
print ("Thanks for registering with [url]www.z.com[/url] <?php echo $firstname; ?> , we have sent you a email with instructions
on how to activate your account.");
}
?>
-
Aug 13th, 2004, 07:12 PM
#2
I don't understand what you want to do. Check the user has entered a first name in the forma that submitted the user name and password?
If the code above doesn't work, it is becuase it has errors in the last print statment. You need to escape double quotes with backslashes.
-
Aug 13th, 2004, 07:59 PM
#3
Thread Starter
Frenzied Member
Originally posted by visualAd
I don't understand what you want to do. Check the user has entered a first name in the forma that submitted the user name and password?
If the code above doesn't work, it is becuase it has errors in the last print statment. You need to escape double quotes with backslashes.
Sorry, the above works well but the user right now can leave out a field such as... let's say firstname.. now if I want to add a line in there to stop them maybe a if $firstname == "" then something..... but not to sure how to add it to this code
-
Aug 14th, 2004, 03:28 AM
#4
Yeah that is what you do. If a user enters nothing, then the string will be blank, so a check like this will suffice:
PHP Code:
if ($firstname == '') {
die ('You must enter a First Name');
}
You can also do a simple client side check too, using javascript.
P.s: If I were you I would turn off register globls and use addslashes() to escape variables, bcause your script is vunerable to SQL injections, whereby a user could gain access your system.
-
Aug 14th, 2004, 11:18 AM
#5
Stuck in the 80s
Also, if you're not going to turn of register_globals, decide on whether you want to use $regular globals or superglobals ($_POST['superglobals']), because using both just makes your code look silly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|