我尝试将edit1.php中的数据更新为setswim.php 但它给出了一个错误: 警告:mysqli :: query():第13行的C:\ xampp \ htdocs \ admin \ setswim.php中的空查询
edit1.php
<html>
<body>
<center>
<?php
$d=$_GET['id'];
include "includes/db.php";
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if ($result = $con->query("SELECT * FROM students WHERE student_number='".$d."'"))
{
if ($result->num_rows > 0)
{
while ($row = $result->fetch_object())
{
$number= $row->student_number;
$n= $row->student_name;
$d= $row->student_last;
$a= $row->id_student;
$b= $row->student_address;
$c= $row->student_collage;
$d= $row->student_datebirth;
$price= $row->student_email ;
}
}
else
{
echo "No results to display!";
}
}
?>
<html>
<body ><center>
<form action="setswim.php?id='"<?php echo $d;?>"' method="post" enctype="multipart/form-data">
<BR><BR><BR><font color="red">
number: <input type="text" name="student_number" value="<?php echo $number;?>"> <br>
student_name: <input type="text" name="student_name" value="<?php echo $n;?>"> <br>
student_last: <input type="text" name="student_last" value="<?php echo"$d";?>"> <br>
id student: <input type="text" name="id_student" value="<?php echo $a;?>"> <br>
student address: <input type="text" name="student_address" value="<?php echo $b;?>"> <br>
student collage: <input type="text" name="student_collage" value="<?php echo $c;?>"> <br>
birthday: <input type="text" name="student_datebirth" value="<?php echo $d;?>"> <br>
student_email: <input type="text" name="student_email" value="<?php echo"$price";?>"> <br>
<BR><BR><BR>
<br><input type="submit" name="submit" value="submit">
</form>
</center>
</font>
</center>
<?php include("adding.php"); ?>
</body>
</html>
&#13;
和setswim.php
<?php
include "includes/db.php";
$checklogin = mysqli_query($con,"SELECT * FROM `students`");
?>
<?php
if(isset($_POST['submit'])) {
$sql=mysqli_query($con,"UPDATE students SET student_number='".$_POST['student_number']."',student_name='".$_POST['student_name']."',student_last='".$_POST['student_last']."',id_student='".$_POST['id_student']."',student_address='".$_POST['student_address']."',student_collage='".$_POST['student_collage']."',student_datebirth='".$_POST['student_datebirth']."',student_email='".$_POST['student_email']."'");
// $result = mysqli_query($con,$sql);
$result = $con->query($sql);
if (!$result) {
mysqli_error($con)."[ $sql]";
}
}
?>
&#13;
<?php
include "includes/db.php";
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if ($result = $con->query("SELECT * FROM students "))
{
if ($result->num_rows > 0)
{
echo "<table border='1' cellpadding='11'>";
echo " <tr> <th><font color=green size=3>Number of Student</font></th><th><font color=red size=5>Name</font></th> <th><font color=red size=5>Last Name</font></th> <th><font color=red size=5>id student</font></th> <th><font color=red size=5>emaill</font></th><th><font color=red size=5>Address</font></th><th><font color=red size=5>Collage</font></th><th><font color=blue size=5>Date Birth</font></th><th><font color=red size=5>Edit</font></th><th><font color=red size=5>Delete</font></th> </tr>";
while ($row = $result->fetch_object())
{
echo "<tr>";
//echo "<td>" . $row->ID. "</td>";<th>ID</th>
echo "<td style='test-align:center;'><small><strong>" . $row->student_number . "</small></strong></td>";
echo "<td style='test-align:center;'><small>" . $row->student_name . "</small></td>";
echo "<td style='test-align:center;'><small>" . $row->student_last . "</small></td>";
echo "<td style='test-align:center;'><strong>ID:</strong><small> ".$row->id_student. "</small></td>";
echo "<td style='test-align:center;'><small>" . $row->student_email . "</small></td>";
echo "<td style='test-align:center;' ><small>" . $row->student_address. "</small></td>";
echo "<td style='test-align:center;' ><small>" . $row->student_collage. "</small></td>";
echo "<td style='test-align:center;'><small>" .$row->student_datebirth."</small></td>";
echo "<td><a href='edit1.php?id=" . $row->student_number . "'>Edit</a></td>";
echo "<td><a href='delswim.php?id=" . $row->student_number . "'>Delete</a></td></small></small>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo "No results to display!";
}
}
else
{
echo "Error: " . $con->error;
}
$con->close();
?>
</center>
&#13;
错误: 警告:mysqli :: query():第13行的C:\ xampp \ htdocs \ admin \ setswim.php中的空查询
答案 0 :(得分:1)
问题在这里
$sql = mysqli_query($con, "UPDATE students ...");
$result = $con->query($sql);
mysql结果存储在$sql
中,然后用作query()
中的字符串。
只需要
$result = mysqli_query($con, "UPDATE students ...");
或
$result = $con->query("UPDATE students ...");
但不是两者兼而有之。我会使用$con->query();