我試圖從文本框代碼中獲取條目以轉到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