我正在尝试通过带有PHP脚本的html表单添加信息并且不会出现任何错误并且它会一直运行并且表现得像进入但数据库上没有任何内容。无论如何都要从这段代码中判断出是否存在我遗漏的东西。
<?php
$servername = "localhost";
$username = "root";
$password = "Kyrarose1";
$dbname = "Senior Project";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$ID = $_POST['ID'];
$ProjectTitle = $_POST['Project Title'];
$ProjectDescription = $_POST['Project Description'];
$ProjectObjective = $_POST['Project Objective'];
$ProjectScope = $_POST['Project Scope'];
$ProjectDate = $_POST['Date'];
$FirstName = $_POST['Firt name'];
$LastName = $_POST['Last name'];
$StudentId = $_POST['Student ID'];
$sql = "INSERT INTO ProjectObjectives ('ID','ProjectTitle', 'ProjectDescription', 'ProjectObjectives', 'ProjectScope', 'ProjectDate', 'Date', 'Fname', 'Lname', 'Student_Id') VALUES ('$ID', '$ProjectTitle', '$ProjectDecription', '$ProjectObjective' '$ProjectScope', '$ProjectDate', '$FirstName', '$LastName', '$StudentId')";
header("refresh:2; url=index.html");
?>
<html>
<head>
<title>Title</title>
<head>
<body>
<form action="Insert.php" method="post">
ID <input type="text" name="Id">
<br>
Project Title: <input type="text" name="ProjectTitle" size="35">
<br>
<br/>
First Name: <input type="text" name="Fname">
<br>
<br/>
Last Name: <input type="text" name="Lname">
<br>
<br/>
Student ID: <input type="text" name="Student_Id">
<br>
<br/>
Project Description: <input type="text" name="ProjectDescription">
<br>
<br/>
Project Objective: <input type="text" name="ProjectObjective">
<br>
<br/>
Project Scope: <input type="text" name="ProjectScope">
<br>
<br/>
Date: <input type="text" name="Date">
<br>
<br/>
Milestones: <input type="text" name="Milestones">
<br>
<br/>
Deliverables: <input type="text" name="Deliverables">
<br>
<br/>
Date:<input type="text" name="Date">
<br>
<br/>
<br>Roles:<br/>
<br><br/>
Name: <input type="text" name="Name">
<br>
<br/>
Role: <input type="text" name="Role">
<br>
<br/>
Email: <input type="text" name="Email">
<br>
<br/>
Phone Number: <input type="text" name="Phone">
<br>
<br/>
Responsibilities: <input type="text" name="Responsibilities">
<br>
<br/>
<br>Resources:<br/>
<br><br/>
Resource: <input type="text" name="Resource">
<br>
<br/>
Hours: <input type="text" name="Hours">
<br>
<br/>
Risks: <input type="text" name="Risks">
<br>
<br/>
Strategy: <input type="text" name="Strategy">
<br>
<br/>
Constraints: <input type="text" name="Constraints">
<br>
<br/>
<input type="submit" value="Submit">
</form>
</body>
</head>
</head>
</html>
答案 0 :(得分:0)
您在INSERT语句中列出了10个数据库列,后面只列出了9个值(变量) - 这些列无效。
答案 1 :(得分:0)
这是mysqli程序风格:
<?php
$conn = mysqli_connect("localhost", "root", "", "xyz");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$x = "x";
$y = "y";
$z = "z";
/* create a prepared statement */
$stmt = mysqli_prepare($conn, "INSERT INTO example324 (x,y,z) VALUES (?,?,?)");
/* bind parameters for markers */
/* sss means has 3 corresponding variable type string */
mysqli_stmt_bind_param($stmt, "sss", $x, $y,$z);
/* execute query */
mysqli_stmt_execute($stmt);
printf("%d Row inserted.\n", mysqli_stmt_affected_rows($stmt));
/* close statement */
mysqli_stmt_close($stmt);
/* close connection */
mysqli_close($conn);
?>
有关此内容的更多信息http://php.net/manual/en/mysqli-stmt.bind-param.php