Check if insert is there.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gimpy
Forum Commoner
Posts: 42
Joined: Tue Jun 14, 2005 1:12 am
Location: Fort Worth, TX, US
Contact:

Check if insert is there.

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Check if insert is there.

Post 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";
}
 
Gimpy
Forum Commoner
Posts: 42
Joined: Tue Jun 14, 2005 1:12 am
Location: Fort Worth, TX, US
Contact:

Re: Check if insert is there.

Post 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?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Check if insert is there.

Post 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().
Post Reply