Dear friends,
Form doesn't write to mysql database. I have pasted code of mysal table
structure,html form and php script. Any comments, please.
------------------------------------------------------------------------------
--------------------
mysql> describe testtable;
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| id | int(4) | | PRI | NULL | auto_increment |
| testField | varchar(10) | | | | |
| testFielda | varchar(10) | | | | |
| testFieldb | varchar(10) | | | | |
| testFieldd | varchar(10) | | | | |
| testFieldc | varchar(10) | | | | |
| testFielde | varchar(10) | | | | |
+------------+-------------+------+-----+---------+----------------+
7 rows in set (0.80 sec)
---------------------------------------------------------------------
//html form code
<HTML>
<HEAD>
<TITLE>Insert Form</TITLE>
</HEAD>
<BODY>
<FORM ACTION="insert.php" METHOD=POST>
<P>Question<input type=text name="testField" size=30> <br>
<P>Answer1<input type=text name="testFielda" size=30> <br>
<P>Answer2<input type=text name="testFieldb" size=30> <br>
<P>Answer3<input type=text name="testFieldc" size=30> <br>
<P>Answer4<input type=text name="testFieldd" size=30> <br>
<P>correct answer<input type=text name="testFielde" size=30> <br>
<p><input type=submit name="submit" value="Insert Record"></p>
</FORM>
</BODY>
</HTML>
------------------------------------------------------------------
//php code
<?php
// open the connection
$conn = mysql_connect("localhost", "", "");
// pick the database to use
mysql_select_db("testDB",$conn);
// create the SQL statement
$sql = "INSERT INTO testtable values ('{'', $_POST['testField']}','
{'', $_POST['testFielda']}','{'', $_POST['testFieldb']}','{'',
$_POST['testFieldd']}','
{'', $_POST['testFieldc']}','{'', $_POST['testFielde']}')";
// execute the SQL statement
if (mysql_query($sql, $conn)) {
echo "record added!";
} else {
echo "something went wrong";
}
?>