Page 1 of 1

Check if insert is there.

Posted: Sat Jun 14, 2008 4:41 am
by Gimpy
Note: Ive tried looking for this but to many posts and not enough keywords and the fact that it 04.40 in the morning. So please forgive me.

Okay, Ive been working on this for a bit and it bugging me.

Code: Select all

 
$file = mysql_query ("INSERT INTO contacts (nick, fname, lname, email, phnum, cellnum, uid) VALUES ('$nick', '$fname', '$lname', '$email', '$phnum', '$cellnum', '$uid')", $con);
mysql_close($con);
 
if ($file = 1){
}
 else { echo "Contact not saved";
 }
header("location: home.php");
When I do the check it goes to the home.php. I have a feeling that in the If statement, that it is checking if the file connect. I need to make it to where the If statement actually inserted the form.

Thanks in advance for any tips and or suggestions.
Bryan

Re: Check if insert is there.

Posted: Sat Jun 14, 2008 4:44 am
by onion2k
Your redirect isn't in your if..else block..

Code: Select all

if ($file = 1) {
  header("location: home.php");
} else {
  echo "Contact not saved";
}
 

Re: Check if insert is there.

Posted: Sat Jun 14, 2008 4:49 am
by Gimpy
Thank you for the quick reply. but the form isnt even inserting into the database, so the if statement only works on the connection. Any ideas on how to get it to work on the actual insert?

Re: Check if insert is there.

Posted: Sat Jun 14, 2008 10:09 am
by onion2k
Echo the SQL statement and see if you can see what the problem. Echo mysql_error() too. And escape your input data with mysql_real_escape_string().