【发布时间】:2013-11-28 03:18:04
【问题描述】:
我试图使用基本的 php 将数据从 html 表单插入到 mysql 表中。我最初使用基本的纯文本输入是成功的。但是,当我尝试输入电子邮件 ID 时,我不断收到此错误:
Could not enter data: 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 '@gmail.com,moohawks )' at line 3
我的php代码如下:
$firstname = $_REQUEST['firstname'];
$lastname = $_REQUEST['lastname'];
$emailid = $_REQUEST['emailid'];
$team_name = $_REQUEST['team_name'];
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'incredible';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = "INSERT INTO users
(firstname,lastname,emailid,teamname)
VALUES ( $firstname,$lastname,$emailid,$team_name )";
mysql_select_db('adb project');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
$message2 = "Entered data successfully\n";
mysql_close($conn);
?>
我的插入语句有什么问题。据我所知,它看起来正确且相当简单。有什么帮助吗?
【问题讨论】:
标签: php html mysql database forms