Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

php mysql perintah UPDATE tidak akan diperbarui

Saya pikir BookingID itu bilangan bulat, jadi baris pembaruan Anda harus:

$updatequery = mysqli_query($con, "UPDATE booking SET FirstName='" . $_POST['txtfirstname'] . "' WHERE BookingID=" . $_POST['txtid'] . ""); //excute UpDate Query

EDIT: Saya menguji skrip Anda dan masalahnya adalah Anda menutup formulir di luar loop sementara. Sekarang berfungsi

<!DOCTYPE html> 

<head>
    <title>Edit Students</title>
</head>

<?php

        $user = 'root';     //Database username ("Root for xampp")
        $pass = '';             //Database password ("empty for exampp")
        $db = 'all_tests';      //Name of database

        $con = new mysqli('localhost', $user, $pass, $db) or die("Unable to connect");         //Create new data connection ('name of host/server', user, password, database name)

        if (isset($_POST['btnUpdate'])) {   //Once Update button pressed perform this  code

            $updatequery = mysqli_query($con, "UPDATE test_1 SET FirstName='" . $_POST['txtfirstname'] . "' WHERE BookingID='" . $_POST['txtid'] . "'"); //excute UpDate Query

        };  

        $sql = mysqli_query($con, "SELECT *FROM test_1"); //Select All from Booking

    //Create Headers for table

echo "<table border='1'>                
<tr>
    <th></th>
    <th>Booking ID</th>
    <th>First Name</th>

</tr>";

//Show Edit Form///////////////////////////////////////////////////////////////////////////////////////////////////
while($row = mysqli_fetch_array($sql)) {    //Run sql code till there are no more rows to import 

echo "<form method=post>";    //Run update code at top of this page

//Populate table with query (sql)

echo "<tr>";
    echo "<td> <input name='btnUpdate' type='submit' value='update' /> </td>";           //once press update row this button is apart of
    echo "<td> <input type='text' value=" . $row['BookingID'] . " name='txtid' /> </td>";
    echo "<td> <input type='text' value=" . $row['FirstName'] . " name='txtfirstname' /> </td>";

echo "</tr>";
echo "</form>";
}


echo "</table>";



mysqli_close($con);     //Close connection

?>



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Bagaimana cara MEMILIH berdasarkan MAX (tanggal)?

  2. MySQL GROUP &COUNT Beberapa tabel

  3. Dapatkan mySQL MONTH() untuk menggunakan angka nol di depan?

  4. Kolom Tabel Ubah MySQL

  5. Bagaimana cara menggabungkan dua baris dan menghitung perbedaan waktu antara dua nilai cap waktu di MySQL?