[英]Using a PHP/HTML form to insert information into 2 MySQL tables
Using a form I am inserting the information from 3 text fields and 2 checkboxes into a MySQL database. 我使用表单将3个文本字段和2个复选框中的信息插入MySQL数据库。
The database consists of 2 tables with the following rows: 该数据库由2个表组成,其中包含以下行:
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语句如下所示:
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. 但是,当我在Web浏览器中访问该页面时,它显示为空白页面。
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. 任何意见是极大的赞赏。
what is mysql_query2 ? 什么是mysql_query2? are you sure you put semicolon after query ?
您确定在查询后输入分号吗?
mysql_query("INSERT INTO articles_tags SET articletags='$articletags' ");
Change mysql_query2('*******)
to mysql_query()
and enable your error reporting to check error comes in the code. 将
mysql_query2('*******)
更改为mysql_query()
并启用错误报告以检查代码中是否包含错误。 Echo your query and run directly in database to check any SQL related error. 回显您的查询并直接在数据库中运行以检查任何与SQL相关的错误。
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);
要查看语法错误,请编辑php.ini或将此行添加到代码的顶部
error_reporting(E_ALL);
Change mysql_query2()
to mysql_query()
将
mysql_query2()
更改为mysql_query()
Your SQL sytax is incorrect... 您的SQL语法不正确...
If the data is already in the database you want to use UPDATE. 如果数据已经在数据库中,则要使用UPDATE。
mysql_query("UPDATE articles SET articletitle='$articletitle',
articleorganization='$articleorganization',
articledate='$articledate',
articleurl='$articleurl' ");
mysql_query("UPDATE articles_tags SET articletags='$articletags' ")
This is how you insert data: 这是您插入数据的方式:
mysql_query("INSERT INTO articles (articletitle,
articleorganization,
articledate,
articleurl) VALUES ($articletitle,$articleorganization,$articledate,$articleurl) ");
Note : You should use mysql_error()
to check for syntax errors. 注意 :您应该使用
mysql_error()
检查语法错误。
mysql_query("INSERT INTO articles_tags SET articletags='$articletags' ") OR DIE(mysql_error());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.