我试图将数据插入MySQL,但它无法正常工作。这里没有显示任何错误。
<?php
$connection = mysqli_connect("localhost", "root", "");
if(!$connection) {
echo 'Server Not Found';
}
else {
echo 'Server Found';
}
// Establishing Connection with Server
$db = mysqli_select_db($connection,"colleges"); // Selecting Database from Server
if (!$db) {
echo 'Databaje Not Found';
}
else {
echo 'Databaje found';
}
if(isset($_POST['submit'])) { // Fetching variables of the form which travels in URL
$name = $_POST['name'];
$email = $_POST['email'];
$contact = $_POST['contact'];
$address = $_POST['address'];
if($name !=''||$email !='') {
//Insert Query of SQL
$query = mysqli_query("insert into students(student_name, student_email, student_contact,student_adress) values ('$name', '$email', '$contact', '$address')", $connection);
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}
else {
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
mysqli_close($connection); // Closing Connection with Server
?>
答案 0 :(得分:0)
在$ query中,首先编写$ connection,然后编写插入查询afyer,添加逗号。这会有所帮助。如果$ query仍然失败,也可以使用mysqli_error()函数查看查询中的错误。