我试图从文本框代码中获取条目以转到php表单并将php表单发送到数据库。我遇到的问题是发布文本框的值,而不是发布$ code。我使用mysql和php。发布变量值而不是变量的名称
PHP:
<?
if($_POST)
{
$username="***";
$password="***";
$con = mysql_connect("***",$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("inmoti6_mysite", $con);
$code = $_POST['code'];
$code = htmlspecialchars($code);
$query = 'INSERT INTO `storycodes`.`storycodes` (`code`) VALUES ("$code");';
mysql_query($query);
echo "<h2>Thank you for your Comment!</h2>";
mysql_close($con);
}
?>
怀疑这是问题,但这里的HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Database</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="/scripts/database2.php">
<label>Code:
<input name="code" type="text" id="code" value="" size="45" />
</label>
<p>
<label>
<input type="submit" name="submit" id="submit" value="Submit" />
</label>
</p>
</form>
</body>
</html>
如果我错了,请更正我的错误,但引号内变量的字面用法仅适用于双引号。 – TheDeadLike