I am trying to post into a database table, 3 different bits of information, but I get an error of Column count doesn't match value count at row 1
Here’s my database table structure:
interestID int(11) auto_increment
name varchar(100)
categoryID int(11)
interest_desc varchar(30)
date timestamp
The form:
<form id="form_design" method="post" action="interesting.php">
<fieldset id="input_1">
<input type="text" id="username" value="name?" />
</fieldset>
<fieldset id="input_2">
<input type="text" id="interest" value="your interest?" />
</fieldset>
<fieldset id="input_3>
<select id="cats">
<option value="">--</option>
<?php
$sql = "SELECT categoryID, category_desc FROM categories "."ORDER BY category_desc"; $rs = mysql_query($sql);
while($row = mysql_fetch_array($rs))
{
echo "<option value=\"".$row['categoryID']."\">".$row['category_desc']."</option>\n "; }
?>
</select>
</fieldset>
<input type="submit" name="submit" value="Submit" />
</form>
The php that inserts it into the table retrieves a column count doesn’t match value count at row 1
PHP –
$interest_user = $_POST['username'];
$interest_name = $_POST['interest'];
$interest_cats = $_POST['cats'];
mysql_query("INSERT INTO interests ( interestID, name, categoryID
, interest_desc, date )
VALUES( "",'$interest_user' '$interest_cats'
, '$interest_name', "" ) ")
or die(mysql_error());
Missing a comma between
'$interest_user' '$interest_cats'should be
more problem :-
Are you sure you are not getting syntax error?
Should be :-
Basic problem is solved,
your way of insertion is vulnerable for SQL injection
Here are the list you MUST do some reading:- https://stackoverflow.com/search?q=sql+injection