出于某种原因,我无法将 POST 字符串值或与此相关的任何值发送到我的数据库,所有列都使用长度正确的 varchar,并且我很确定我正确设置了 SQL 查询语句。我已经查看并找到了与此相关的已回答问题,但它仍然无法正常工作,而且我还多次通过PHP 验证器运行它,没有语法错误。
下面是我的代码:
应用.php
<?php
$required = array('name', 'age', 'position', 'email', 'desc');
$name= $_POST["name"];
$age= $_POST["name"];
$email= $_POST["email"];
$position= $_POST["position"];
$desc= $_POST["desc"];
$error = false;
foreach($required as $field) {
if (empty($_POST[$field])) {
$error = true;
}
}
if ($error) {
echo "You must fill in all fields";
}
else {
echo "Application Submitted, You will receive an email with a validation code in 1-2 days </br>Ask the owner in game for faster service";
mysqli_connect("localhost","root","password","apply");
mysqli_query("INSERT INTO applications (name, age, email, position, desc) VALUES ('$name', '$age', '$email', '$position', '$desc')");
mysqli_close();
}
?>
read_database.php
<?php
$username="root";
$password="password";
$database="apply";
mysql_connect(localhost,$username,$password);
$result = mysqli_query("SELECT * FROM applications") ;
echo "<table border='1'>
<tr>
<th> Name </th>
<th> Age </th>
<th> Email Address </th>
<th> Position </th>
<th> Reasoning </th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['position'] . "</td>";
echo "<td>" . $row['desc'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close();
?>