我的代码在 MySQL 表“activate”中插入了一条空记录,而不是获取数据 activate.html。它调用了我删除的activate.php。我还应该补充一点,我是 php 新手,但知道注入攻击。我最初解决了一些安全问题,但正如我所说,已经剥离了代码以找到问题的根源。此外,当我回显表单字段时,它们会填充,而不是填充到 MySql 表中。任何想法为什么?先感谢您。
<?php
$host = "host"; // Host name
$username = "user"; // Mysql username
$password = "pass"; // Mysql password
$db_name = "db"; // Database name
$tbl_name = "activate"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name") or die("cannot select DB");
// Get values from form
if (isset($_POST['submit'])) {
$esn = mysql_real_escape_string($_POST['esn']);
$esnverify = mysql_real_escape_string($_POST['esnverify']);
$zip = mysql_real_escape_string($_POST['zip']);
$comments = mysql_real_escape_string($_POST['comments']);
}
// Insert data into mysql
$sql = "INSERT INTO $tbl_name (esn, esnverify, zip, comments) VALUES ('$esn', '$esnverify', '$zip', '$comments')";
$result = mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if ($result) {
echo "Successful";
echo "<br />";
echo $_POST['esn'];
echo "<br />";
echo $_POST['esnverify'];
echo "<br />";
echo $_POST['zip'];
echo "<br />";
echo $_POST['comments'];
echo "<br />";
echo "<a href='thankyou.html'>Back to main page</a>";
}
else {
echo "ERROR";
}
?>
<?php
// close connection
mysql_close();
?>
激活.html
<form method="post" action="activate.php">
<p><b>ESN:</b> <input type="text" id="esn" name="esn" maxlength="50"><br/>
<b>Confirm ESN:</b> <input type="text" name="esnverify" id="esnverify" maxlength="50"><br/>
<b>Zip:</b> <input type="text" name="zip" id="zip" maxlength="5"><br/>
<p>Your comments:<br />
<textarea name="comments" rows="10" cols="40" id="comments" maxlength="500"></textarea></p>
<p><input type="submit" value="Send it!"></p></form>