zero-perfoliate
zero-perfoliate

Author Topic: Adding data to MySQL  (Read 474 times)

Offline dvlchd3

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
Adding data to MySQL
« on: November 28, 2008, 04:08:29 PM »
Hello all.
I am attempting to write a simple form to collect information from a user, and then add that data to my MySQL database.  However, I am running into a problem:

Here is my code after all data has been taken care of for magic quotes, etc:
Code: [Select]
// Check for pervious addition.
$query = "SELECT cid FROM contacts WHERE email='$e'";
$result = mysql_query($query);
if (mysql_num_rows == 0) {

// Make the query.
$query = "INSERT INTO contacts (first_name, last_name, phone1, phone2, address1, address2, city, state, zip, email) VALUES ('$fn', '$ln', '$p1', '$p2', '$a1', '$a2', '$c', '$s', '$z', '$e')";
if ($result) { // If it ran OK.

// Print the message.
echo '<h1>Thank You!</h1>
<p>You are now subscribed to your mailing list.</p>
<p>Result: ' . $result . '</p>
<p>Error: ' . mysql_error() . '</p>';

// Include the footer and quit the script (to not show the form.)
include ('./includes/footer.html');
exit();
} else { // It did not run OK.
echo '<h1>System Error!</h1>
<p>You could not be added to our mailing list due to a system error.  We apologize for this inconvenience.</p>'; // Public message.
echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message.
include ('./includes/footer.html');
exit();
}
} else { // already registered.
echo '<h1>System Error!</h1>
<font color="red"><p>The email address you entered is already in our system.</p></font>';
}
The '$result' returns: Resource id #4
I'm not sure if that helps.

I get the message saying I had successfully registered, however, the information does not appear in the database.  It is almost like the query never happened, but the script acts like it did happen.

I really have no idea what is wrong, and would appreciate any help anyone can give me!

Thanks in advance!

DAN

 

zero-perfoliate