Jump to content

Recommended Posts

I'm new to mysql.  I created a form to enter data into a table, but the data does not get into the table.  Here's the form at http://test.paulredwine.com/db2/add_contacts.htm :

<html><body><form action=contact_submit_form.php method=GET>
Contact Type: <select name="Contact Type">
<option value="1">--Contact Type--</option>
<option value="2">Customer - Active</option>
<option value="3">Customer - Inactive</option>
<option value="4">Customer - Canceled</option>
</select><br>
Name (Last, First): <input type=text name=Name size=25 maxlength=25><br>
Address: <input type=text name=Address size=25 maxlength=25><br>
City: <input type=text name=City size=25 maxlength=25><br>
State: <input type=text name=State size=25 maxlength=25><br>
Postal Code: <input type=text name=PostalCode size=25 maxlength=25><br>
<p>
<input type=submit>
</form></body></html>

and here is contact_submit_form.php: 
<html>
<body>
<?php 
mysql_connect (localhost, predwine_test, jazz77);
mysql_select_db (predwine_test);
mysql_query ("INSERT INTO contacts (contactType, Name, Address, City, State, PostalCode) 
VALUES ('$ContactType', '$Name', '$Address', '$City', '$State', '$PostalCode')
");
print ($ContactType);
print (" ");
print ($Name);
print ("<p>");
print ("Thanks for your submission.");
?>
</body></html>

It appears that the form works, because I get the confirmation, "Thanks for your submission" but the data never reaches the database table.

Please use the forum code tags

 

The way you have it, it will print no matter what.

I would add some error handling. (The reason it was saying "Thank you..." even with an error)

Also, add or die() for testing

 

$connection = mysql_connect (localhost, predwine_test, jazz77);
$db = mysql_select_db (predwine_test);
$sql = "INSERT INTO contacts (contactType, Name, Address, City, State, PostalCode) VALUES ('$ContactType', '$Name', '$Address', '$City', '$State', '$PostalCode')";
$query = mysql_query ($sql) or die(mysql_error());
if (!$query) {
print ("ERROR");
} else {
print ($ContactType]);
print (" ");
print ($Name);
print ("<p>");
print ("Thanks for your submission.");

}

 

Try that and let me know if it helps; it's not tested and just what I noticed at first glance

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.