Using a form I am inserting the information from 3 text fields and 2 checkboxes into a MySQL database.
The database consists of 2 tables with the following rows:
id - articletitle - articleorganization - articledate - articleurl
id - article_tags - articlid - tagid
The checkboxes use an array and are coded thus:
<input type="checkbox" name="articletags[]" value="geology" id="articletags_0" />
<input type="checkbox" name="articletags[]" value="astronomy" id="articletags_1" />
And the MySQL statement looks like this:
mysql_query("INSERT INTO articles SET articletitle='$articletitle',
articleorganization='$articleorganization',
articledate='$articledate',
articleurl='$articleurl' ")
mysql_query2("INSERT INTO articles_tags SET articletags='$articletags' ")
However, when I visit the page in a web browser it shows a blank page.
In case anyone is wondering, the reason I’m using checkboxes is because the articles will need to be tagged with a combination of tags, and this will ensure that consistency is used in the tagging. Also, I have a form used to edit the articles, and the database structure could, I believe, be used to make the checkboxes “checked” on the edit page.
Any advice is greatly appreciated.
The blank page is actually from a syntax error. To see syntax errors, edit the php.ini or add this line to the top of your code
error_reporting(E_ALL);Change
mysql_query2()tomysql_query()Your SQL sytax is incorrect…
If the data is already in the database you want to use UPDATE.
This is how you insert data:
Note: You should use
mysql_error()to check for syntax errors.