0
我发现下面的脚本出于某种原因挂起。它会加载和PHP没有看到任何错误,但它不会处理数据(注意我们是在我有一个单独的登录数据库打开的情况下)。为什么下面不显示打开SQL连接?
在process.php中,我们有以下内容:
<? PHP
//Process the POST data in prepration to write to SQL database.
$_POST['chat_input'] = $input;
$time = date("Y-m-d H:i:s");
$ip = $_SERVER['REMOTE_ADDR'];
$name = $_SESSION['username'];
$servername = "localhost";
$username = "id3263427_chat_user";
$password = "Itudmenif1!Itudmenif1!";
$dbname = "id3263427_chat_user";
$id = "NULL";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = 'INSERT INTO `chat` (`id`, `username`, `ip`, `timestamp`,
`message`) VALUES ('$id','$name', '$ip', '$time', '$input')';
if(mysqli_query($link, $sql)){
mysqli_close($conn);
header('Location: ../protected_page.php');
} else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
?>
传递到上面的脚本的HTML格式如下:
<form action="/process.php" method="post" id="chat">
<b> Send A Message (500 Character Max):</b><br>
<textarea name="chat_input" form="chat" size="500"></textarea>
<input type="submit" value=submit>
</form>
不知道发生了什么事与此有关。
你确定要做这个'$ _POST ['chat_input'] = $ input;'而不是'$ input = $ _POST ['chat_input'];'? – pmahomme
我纠正了这一点,对任何事情都没有任何影响。 –
你确定没有错误报告检查你的sql字符串它必须被双引号包围,如果你简单的列名称报价 – douxsey