Php MYSQL-不插入数据库?
我的MYSQL查询没有通过我制作的表单正确插入。查询:Php MYSQL-不插入数据库?,php,mysql,forms,insert,Php,Mysql,Forms,Insert,我的MYSQL查询没有通过我制作的表单正确插入。查询: mysql_query("INSERT INTO Servers(ip, desc, type, title) VALUES($ip, $desc, $type, $title)" ) or die(mysql_error()); MYSQL表如下所示: CREATE TABLE IF NOT EXISTS Servers( id bigint(20) NOT NULL AUTO_INCREMENT, ip varchar
mysql_query("INSERT INTO Servers(ip, desc, type, title)
VALUES($ip, $desc, $type, $title)"
) or die(mysql_error());
MYSQL表如下所示:
CREATE TABLE IF NOT EXISTS Servers(
id bigint(20) NOT NULL AUTO_INCREMENT,
ip varchar(50) NOT NULL,
desc text NOT NULL,
type varchar(15) NOT NULL,
title varchar(50) NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3;
我已经在表中有两行预先制作好的。表格编号:
<form action="" method="post">
Title: <input type="text" name="title" /><br />
IP: <input type="text" name="ip" /><br />
Description:<br />
<textarea name="desc"></textarea><br />
Type: <input type="text" name="type" /><br />
<input type="submit" name="submit" value="Submit server!" />
</form>
试试这个
mysql_query("INSERT INTO `Servers` (`ip`, `desc`, `type`, `title`) VALUES('".$ip."', '".$desc."', '".$type."', '".$title."')") or die(mysql_error());
desc
是MySql的保留关键字,因此如果没有反勾号,就无法使用它。试试这个
mysql_query("INSERT INTO `Servers` (`ip`, `desc`, `type`, `title`) VALUES('".$ip."', '".$desc."', '".$type."', '".$title."')") or die(mysql_error());
desc
是MySql的保留关键字,因此如果没有反勾号,就无法使用它。插入字符串值时应该使用引号:
mysql_query("INSERT INTO Servers(ip, desc, type, title) VALUES('$ip' , '$desc', '$type', '$title')") or die(mysql_error());
插入字符串值时应使用引号:
mysql_query("INSERT INTO Servers(ip, desc, type, title) VALUES('$ip' , '$desc', '$type', '$title')") or die(mysql_error());
desc是保留的工作,您必须使用``。如果字段是(var)字符,而不是数字,
您必须在脚本中用引号将其括起来。desc是保留的作品,您必须使用```。如果字段是(var)字符,而不是数字,
您必须在脚本中用引号将其括起来。谢谢!我混合使用了你的答案和罗尔的答案,现在效果非常好!谢谢我混合使用了你的答案和罗尔的答案,现在效果非常好!顺便说一句,你不需要把尖括号换成方括号。只需在html代码块前面加上四个空格,并确保它有一个前后回车符。顺便说一句,您不需要将尖括号换成方括号。只需在html代码块前面加四个空格,并确保它有前后回车符。