Home > Net >  When I click the button, I want to update the database
When I click the button, I want to update the database

Time:12-17

I want to create a process in which the database is updated by pressing the button. However, when you write it like the code below, when you click the button, it goes to the admin_cp.php page. The page froze, and the contents of the database remained unchanged. What's the problem with my code?

admincharge.php

<form action="admin_cp.php" method="POST" onsubmit="return confirm('Charging handle?');"> 
    <input type="submit" neme="charge"/>
</form>

admin_cp.php

include('Aconfig.php');
if (isset($_POST["charge"])){ 
    $query = "UPDATE userinfo
        INNER JOIN chargeINFO ON (userinfo.u_id = chargeINFO.u_id)
        SET userinfo.u_charged = chargeINFO.u_chargewait;";
    $result = mysqli_query($conn, $query);
    if ($result) {
        echo "<script>alert('Charged complete.')</script>";
        echo "<meta http-equiv='refresh' content='0;url=admincharge.php'>";
    } else {
        echo "<script>alert('fail')</script>";
        echo "<meta http-equiv='refresh' content='0;url=admincharge.php'>";
    }
}

CodePudding user response:

have you checked this part:

$query = "UPDATE userinfo
        INNER JOIN chargeINFO ON (userinfo.u_id = chargeINFO.u_id)
        SET userinfo.u_charged = chargeINFO.u_chargewait;";

at the end of .unchargewait;"; delete ; so it looks like this:

$query = "UPDATE userinfo
        INNER JOIN chargeINFO ON (userinfo.u_id = chargeINFO.u_id)
        SET userinfo.u_charged = chargeINFO.u_chargewait";
  • Related