Difficulty Inserting from HTML form into MySQL (created in Workbench)
Posted
by
Chaya Cooper
on Stack Overflow
See other posts from Stack Overflow
or by Chaya Cooper
Published on 2011-11-21T23:22:31Z
Indexed on
2011/11/22
1:50 UTC
Read the original article
Hit count: 166
I created a MySQL database in Workbench 5.2.35 for purposes of storing and using information submitted in html forms but I'm having difficulty inserting records from the html form.
The relevant SQL script was saved as Demo2.sql, the schema is C2F, and the table is customer_info. I wasn't sure if that was the problem, so I tried replacing the database name (Demo2) with the schema name, but that didn't work either.
My html file includes: form action="insert.php" method="post"
The insert.php file states:
?php $con = mysql_connect("localhost","root","****"); if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("Demo2", $con);
$sql="INSERT INTO customer_info(fname, lname, user, password, reminder, answer) VALUES ('$_POST[fname]','$_POST[lname]','$_POST[user]','$_POST[password]','$_POST[reminder]','$_POST[answer]')";
if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added";
mysql_close($con) ?
I've also tried INSERT INTO c2f.customer_info(fname, lname, etc. and INSERT INTO 'c2f'.'customer_info'
© Stack Overflow or respective owner