为什么PHP脚本插入MySQL数据库失败? [英] Why does PHP script fail to insert into MySQL database?
本文介绍了为什么PHP脚本插入MySQL数据库失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想弄清楚为什么当我的 PHP 脚本尝试将数据插入 MySQL 数据库时会发生错误.
I am trying to figure out why an error occurs when my PHP script tries to insert data into a MySQL database.
我正在处理一个收集数据的小表单,然后在 PHP 中将其提交到我的 SQL 数据库中.当我提交它时,我得到一个空白页并且没有插入任何内容,如果插入失败,我添加了一个回显以显示,它是.
I am working on a small form that collects data, and then in PHP I submit it into my SQL database. When I submit it, I get a blank page and nothing is inserted, I have added an echo to display if the insert fails, which it is.
<?php
mysql_connect("host", "user", "pass") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
$name=$_POST['repname'];
$replace=$_POST['replace'];
$reg=$_POST['reg'];
info=$_POST['info'];
if($name == '') {
$errmsg_arr[] = 'Rep name missing.';
$errflag = true;
}
if($replace == '') {
$errmsg_arr[] = 'Please fill out all the forms.';
$errflag = true;
}
if($reg == '') {
$errmsg_arr[] = 'Please fill out all the forms.';
$errflag = true;
}
if($info == '') {
$errmsg_arr[] = 'Please add some other information about your rep.';
$errflag = true;
}
if(!mysql_query("INSERT INTO reps (name, replace, reg, boxinfo) VALUES
('".$name."','".$replace."','".$reg."','".$info."')"))
{
echo 'failed';
}
else
{
echo 'inserted';
}
?>
推荐答案
Beside Shankar 的评论 replace
是一个保留字 使用反引号.
Beside Shankar's comment replace
is a reserved word use backticks.
INSERT INTO reps (name, `replace`, reg, boxinfo)
这篇关于为什么PHP脚本插入MySQL数据库失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文