简体   繁体   中英

I can't update my database with php

I'm try to update data on table It's can't update , but It can send data to the last section before SQL command to update.

This is my button on the first page

<a href="Edit.php?Edit=<?php echo $UID; ?>" onclick="document.getElementById('bgmodal');"><i class="fa fa-edit" style="font-size:20px;color:Green;"></i></a>

and this is my update page

บันทึก means "Save"

แก้ไขข้อมูล means "Data edit"

โปรดตรวจสอบข้อมูลก่อนบันทึก means "Pls check before save"

ต้องการบันทึกข้อมูลนี้หรือไม่? means " Are you want to save?"

<?php
include('connect.php');
    if (isset($_GET['Edit'])) {
    $editid = $_GET['Edit'];
    $rez = $mysqli->query("SELECT * FROM user_tbl WHERE User_ID ='$editid'");
    $resut = mysqli_fetch_array($rez,MYSQLI_ASSOC);
    $UsID = $resut['User_ID'];
    $UsName = $resut['User_Name'];
    $Dpt = $resut['Dept_ID'];
}
?>
    <div id="bgmodal" class="bg-modal">
        <div id="modalcont" class="bg-content">
            <a href="User.php" class="close"  >+</a>
                <form method="GET" action="Edit.php" >
                    <H1 style="font-family: sans-serif; text-decoration: underline;" >แก้ไขข้อมูล</H1>
                    <h2 style="font-family: sans-serif; color: red; font-size: 20px" >**โปรดตรวจสอบข้อมูลก่อนบันทึก**</h2>
                    <input class="IP1" type="text" name="Users_text" value="<?php echo $UsID ?>">
                    <input class="IP1" type="text" name="Uname_text" value="<?php echo $UsName ?>">
                    <input class="IP1" type="text" name="Dpart_text" value="<?php echo $Dpt ?>">
                    <input class="btn" type="submit" name="Edited" value="บันทึก" onclick="return confirm('ต้องการบันทึกข้อมูลนี้หรือไม่?');"> 
                </form>
        </div>
    </div>
<?php
    if (isset($_GET['Edited'])){
        $IDu = $_GET['Users_text'];
        $NUs = $_GET['Uname_text'];
        $Dpu = $_GET['Dpart_text'];
        echo "<script> alert('".$NUs."') </script>"; #I'm test for check the data is come to this section
        $mysqli->query("UPDATE user_tbl SET User_ID = '$IDu' , User_Name = '$NUs' ,  Dept_ID = '$Dpu' WHERE User_ID = 'IDu' ") or die (mysqli_error());

    }
?>

Because form send to edit.php and you should take this code to there

<?php
if (isset($_GET['Edited'])){
    $IDu = $_GET['Users_text'];
    $NUs = $_GET['Uname_text'];
    $Dpu = $_GET['Dpart_text'];
    echo "<script> alert('".$NUs."') </script>";
    #I'm test for check the data is come to this section
    $mysqli->query("UPDATE user_tbl SET User_ID = '$IDu' , User_Name = '$NUs' , Dept_ID = '$Dpu' WHERE User_ID = 'IDu' ") or die (mysqli_error());
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM