Jump to content

Why Isn't Insert Into Working?


Krewe

Recommended Posts

Here is my code:

if(isset($_POST['submit'])){   if(isset($_POST['first_name']) && !empty($_POST['first_name']) AND isset($_POST['last_name']) && !empty($_POST['last_name']) AND isset($_POST['email']) && !empty($_POST['email']) AND isset($_POST['retype_email']) && !empty($_POST['retype_email']) AND isset($_POST['username']) && !empty($_POST['username']) AND isset($_POST['password']) && !empty($_POST['password']) AND isset($_POST['retype_password']) && !empty($_POST['retype_password'])){    $username = mysql_prep($_POST['username']);    $password = mysql_prep($_POST['password']);    $retype_password = mysql_prep($_POST['retype_password']);    $hashed_password = sha1($password);    $first_name = mysql_prep($_POST['first_name']);    $last_name = mysql_prep($_POST['last_name']);    $email = mysql_prep($_POST['email']);    $retype_email = mysql_prep($_POST['retype_email']);       if($password == $retype_password){	 if($email == $retype_email){   	  if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){	   // Return Error - Invalid Email	   $msg = "The E-mail you entered is not invalid, please try again.";	  }else{	   // Return Success - Valid Email	   $hashed = md5( rand(0,1000) );	   mysql_query("INSERT INTO users (username, password, email, first_name, last_name, hashed) VALUES ('{$username}', '{$hashed_password}', '{$email}', '{$first_name}', '{$last_name}', '{$hashed}')", $connection);	   $msg = "User Added Succesfully";	  }	 	 }else{	  // Return Error - E-mails do not match	  $msg = "E-mails do not match, please try again.";	 }    }else{	 // Return Error - Passwords do not match	 $msg = "Passwords do not match, please try again.";    }   }else{    $msg = "Some fields were empty, please try again";   }   }

I have double checked it, triple checked and still cant find an error... The code is going all the way to the $msg = "User Added Successfully";So I know it is reading the else part... so why isn't it doing the mysql_query?

Link to comment
Share on other sites

You don't seem to be checking for MySQL errors — check the return value of mysql_error() after doing the query.

Link to comment
Share on other sites

Have you tried querying like this instead:

mysql_query("INSERT INTO users (username, password, email, first_name, last_name, hashed) VALUES ('$username', '$hashed_password', '$email', '$first_name', '$last_name', '$hashed')", $connection);

... without the braces?

Link to comment
Share on other sites

... Synook thanks I feel like a complete idiot xD I miss typed a field name and never realized. Hashed was suppose to be Hash...Thanks to both of ya.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...