텍스트 상자 코드에서 PHP 양식으로 이동하여 PHP 양식에서 데이터베이스로 보내도록하려고합니다. 내가 겪고있는 문제는 $ code를 게시하는 textbox 값을 게시하는 대신에 발생합니다. 나는 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