Database Insert question

I can happily insert form data into the database until I come to a dropdown choice.

I have this bit

Category: <select name="maincat">
<option value="cardmaking">Choose category</option>
<option value="cardmaking">Card Making</option>
<option value="painting">Painting</option>
<option value="toymaking">Toy Making</option>
<option value="dont">Don't Know</option>
</select>

and then this bit…

$sql="INSERT INTO 
gallery (title, description, step1, step2, step3, step4, step5, step6, step7, step8, step9, step10, image1, id, spare, maincat)
VALUES('$_POST[title]','$_POST[description]','$_POST[step1]','$_POST[step2]','$_POST[step3]','$_POST[step4]','$_POST[step5]','$_POST[step6]','$_POST[step7]','$_POST[step8]','$_POST[step9]','$_POST[step10]','$_POST[image1]','$_POST[id]','$_POST[spare]','$_POST[maincat]')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

How do I get the users selection to be added to the database?

Can anyone help please?

Thanks for the advice guys - I still have much to learn :slight_smile:

You may have fixed that issue , but its not fixed in our term .

This code will bring SQL injection . Use atleast mysql_real_escape_string .

Better Tips:

Also think about using numerical IDs instead of the text values.
It may be your category ID. Use the category name text for display only.

Don’t worry I have fixed it. Sorry for rubbish post.