我是PHP新手,我正在製作一個插入函數,它會將html輸入插入到我的Sql數據庫中,但是當我提交任何內容時都沒有任何反應,也沒有任何信息輸入到數據庫中。我非常感謝有關如何將輸入信息提交到數據庫的任何幫助。PHP在提交時不會發送sql數據到數據庫?
<html>
<head>
</head>
<body>
<div align = "center">
<form method = "POST" class="basic-grey">
<h1><i>Insert</i></h1>
<label>Title :<input type = "text" name="title"/></label>
<label>Content :<input type = "text" name="content"/></label>
<label>User :<input type = "text" name="user"/></label>
<label><input type = "submit" value = "submit"/></label>
</form>
<div style = "font-size:11px; color:#cc0000; margin-top:10px"><?php echo $error ?></div>
</div>
</html>
<?php
include_once 'db_config.php';
session_start();
if (!(isset($_SESSION['login_user']) && $_SESSION['login_user'] != '')) {
header ("Location: login2.php");
}
if(isset($_POST["submit"])) {
$title = $_POST['title'];
$content = $_POST['content'];
$user = $_POST['user'];
$sql = "INSERT INTO 'diary' ('ID', 'TITLE', 'CONTENT', 'USER')
VALUES (NULL, '$title','$content', '$user',)";
if ($conn->query($sql) === TRUE) {
header("location: results.php");
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>
數據庫連接成功完成? –
嘗試print_r($ conn-> query($ sql));看看問題是什麼 – 25r43q
不會工作,因爲你沒有任何名爲'submit'的if(isset($ _ POST [「submit」])){'來測試。 –