使用PHP从表单中将数据插入数据库 [英] Inserting Data into a Database from a form using PHP
问题描述
好的,这应该是相当容易的,但由于我缺乏经验,我遇到了很多麻烦。当我将表单中的信息提交到名为insert.php的页面时,我收到以下错误
错误:您的SQL语法中有错误;检查
对应于您的MySQL服务器版本的手册,以获得正确的语法使用
''来自,评论)值('''','''' ,''''''在第1行
这里是我对insert.php的代码
<?php
$ con = mysql_connect(" mysql3.freehostia.com"," ammloc_post s"," sumner20");
if(!$ con)
{
die(''无法连接:''。mysql_error());
}
mysql_select_db(" ammloc_posts",$ con);
$ sql =" insert into two_fridas(Subject,From,Comments)
值(''$ _post [subject]'',''$ post [from]'',''$ _ post [comments]'')" ;;
if (!mysql_query($ sql,$ con))
{
die(''错误:''。mysql_error());
}
echo谢谢你,你的评论已被添加。;
mysql_close($ con);
?>
您还可以在http:// humanities1100看到第一手的样子.freehostia.com / fridas.html,然后填写表格并提交。
任何帮助将不胜感激。提前谢谢你
Okay this should be something fairly easy, but due to my lack of experience I am having a lot of trouble. I am receiving the following error when I submit the information in my form to a page called insert.php
Error: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ''From, Comments) Values ('''','''','''')'' at line 1
here is the code I have for the insert.php
<?php
$con = mysql_connect("mysql3.freehostia.com","ammloc_post s","sumner20");
if (!$con)
{
die(''Could not connect: '' . mysql_error());
}
mysql_select_db("ammloc_posts", $con);
$sql="insert into two_fridas (Subject, From, Comments)
Values (''$_post[subject]'',''$_post[from]'',''$_post[comments]'')";
if (!mysql_query($sql,$con))
{
die(''Error: '' . mysql_error());
}
echo "Thank you, your comment has been added.";
mysql_close($con);
?>
You may also see first hand what it looks like at http://humanities1100.freehostia.com/fridas.html and then just fill out the form and submit.
any help would be greatly appreciated. thank you in advance
推荐答案
con = mysql_connect(" mysql3.freehostia.com"," ammloc_post s"," sumner20");
if(!
con = mysql_connect("mysql3.freehostia.com","ammloc_post s","sumner20");
if (!
con)
{
die(''无法连接:''。mysql_error( ));
}
mysql_select_db(" ammloc_posts",
con)
{
die(''Could not connect: '' . mysql_error());
}
mysql_select_db("ammloc_posts",
con);
con);
这篇关于使用PHP从表单中将数据插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!