Submit an HTML select/dropdown form to MySQL database
11,735
Solution 1
Hmmm...If that doesn't work try:
mysql_query("INSERT INTO table1 VALUES ('".$gender."','".$name."');");
Solution 2
- try to print your form results
- try to print your SQL statement instead of executing
- check the statement by eye
- copy the statement and try to execute in at the server manually.
- add the
log=query.log
option in the[mysqld]
section of MySQL server configuration file (probablymy.cnf
), restart the server and look intoquery.log
for recent queries -- do they reach the server?
Author by
JSW189
Updated on June 13, 2022Comments
-
JSW189 almost 2 years
I am trying to submit an HTML
<form>
and have theinput
andselect
information entered into a MySQL database table. My code is entering the<input type="text">
data into the table, but it is not entering the data in the<select>
.This is the
<form>
I have been using:<form enctype="multipart/form-data" action="send.php" method="post"> <select name="gender"> <option value="Male"> Male</option> <option value="Female">Female</option> </select> <input type="text" name="name"> <input type="submit" value="Add"> </form>
And this is the PHP I've been using to enter the form into the table:
<?php $gender=$_POST['gender']; // This is the select/dropdown $name=$_POST['name']; // This is the text input mysql_connect("", "", "") or die(mysql_error()) ; mysql_select_db("") or die(mysql_error()) ; mysql_query("INSERT INTO `table1` VALUES ('$gender', '$name')") ; ?>
-
llazzaro about 9 yearsyou should avoid using concatenation in queries