PHP表单不更新数据库(mysqli)

时间:2017-05-02 13:04:36

标签: php mysqli

我有一个简单的PHP表单来更新数据库以存储简单信息,但是这个表单由于某种原因没有停止更新数据库,我无法弄清楚原因。

有没有人有任何想法

    <html>
<head>
<title>insert data in database using mysqli</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

<div id="login">
<h2>Data Archive</h2>
<hr/>
<form action="" method="post">
<label>HDD Name  :</label>
<input class="login" type="text" name="hdd_name" id="hdd_name" required="required" placeholder="Please enter HDD name"/><br /><br />
<label>Date Archived  :</label>
<input class="login" type="text" name="date_archived" id="date_archived" required="required"  placeholder="Date data was archived"/><br/><br />
<label>Project Name  :</label>
<input class="login" type="text" name="project_name" id="project_name" required="required"  placeholder="Project name"/><br/><br />
<label>Client  :</label>
<input class="login" type="text" name="client" id="client" required="required"  placeholder="Client name"/><br/><br />
<label>Archived by  :</label>
<input class="login" type="text" name="archived_by" id="archived_by" required="required"  placeholder="Name of person archiving data"/><br/><br />
<label>Editor  :</label>
<input class="login" type="text" name="editor" id="editor" required="required"  placeholder="Editor name"/><br/><br />
<label>Other information  :</label><br/><br />
<textarea class="textarea" name="other_information" id="other_information" wrap="virtual" placeholder="Name of person archiving data"/></textarea><br/><br />
<input class="login" type="submit" value=" Submit " name="submit"/><br />
</form>
</div>

</div>
<?php
if(isset($_POST["submit"])){
$servername = "*********";
$username = "***************";
$password = "***************";
$dbname = "****************";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO data_archive (hdd_name, date_archived, project_name, client, archived_by, editor, other_information)
VALUES (".$_POST["hdd_name"].",".$_POST["date_archived"].",".$_POST["project_name"].",".$_POST["client"].",".$_POST["archived_by"].",".$_POST["editor"].",".$_POST["other_information"].")";

if ($conn->query($sql) === TRUE) {
    echo "<script type= 'text/javascript'>alert('New Record Inserted Successfully');</script>";
} else {
    echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
}

$conn->close();
}
?>
</body>
</html>

0 个答案:

没有答案