someone please help me. i am having people register for my website and my script writes like half the people info into my database and some people and some computers it doesnt! what the heck is wrong! here is my code <?php session_start(); //include file to connect, this is fine $query="SELECT * FROM users WHERE firstname = '$_SESSION[firstname]'"; $result=mysql_query($query); $num = mysql_num_rows($result); if ($num == 0) { $one=strip_tags($_SESSION[firstname]); $two=strip_tags($_SESSION[lastname]); $three=strip_tags($_SESSION[email]); $four=strip_tags($_SESSION[pass]); $query = "INSERT INTO users SET firstname='$one', lastname='$two', email='$three', pass='$four', money='500', job='Peasant'"; $result = mysql_query($query); }else{ header("Location:index.php"); } session_destroy(); ?> Code (markup):
It seems your script insert the new record if :there is no "first name" recordwhich is equal with "$_SESSION[firstname]" in your database. Are you trying to prevent duplicate first name records or something like that ? How does "$_SESSION[firstname]" get filled ?
Also, unless you user empty() to verify that the variables are not null, set the database fields to NULl instead of NOT NULL.
why don't you just check the existence with $query="SELECT * FROM users WHERE email= '$_SESSION[email]'"; PHP: instead of the firstname? replace line 5 with what I gave you. That would be more useful since users shouldn't share an email, but many could share a firstname!