Updating my status

i have a code thats suppose to update my status table to ‘1’ if my amount is equal to balance, but it only runs it once.

here’s the code:

<?php
$id2 = ($_GET['id2']); 
$query = "INSERT INTO paired_members(user_id_1, user_id_2,time,time2) VALUES('".$first_id."','".$id2."','".time()."','".(time()+86400)."')"; //how to insert into a table
$query2 = "UPDATE members_donating SET status = '1'WHERE user_id = $id2 ";
$query3 = "UPDATE account SET status = '1' WHERE user_id = $id2 ";
$query4 = "SELECT initial_payment from account WHERE user_id = $id2 ";
$query5 = "SELECT withdrawal from account WHERE user_id = $first_id ";
$query6 = "SELECT balance from members_receiving WHERE user_id = $first_id";
        
         //Getting the initial withdrawal amount
        $result5 = mysqli_query($connect,$query5);
        $result12 = mysqli_query($connect,$query2);
        $result15 = mysqli_query($connect,$query3);
        $row = mysqli_fetch_assoc($result5);
        $userwithdrawal = $row['withdrawal'];
        ///Getting initial payment value
        $result4 = mysqli_query($connect,$query4);
        $row2 = mysqli_fetch_assoc($result4);
        $initialp = $row2['initial_payment'];
      
		
        /// Getting the balance from receiving users table;
        $result6 = mysqli_query($connect,$query6);
        $row3 = mysqli_fetch_array($result6);
        $balance = $row3['balance'];
        if($balance == $userwithdrawal){
$query7 = "UPDATE account SET status = '1' WHERE user_id = $first_id ";            
$result7 = mysqli_query($connect,$query7);
$query9 = "UPDATE members_receiving SET status = '1' WHERE user_id = $first_id ";            
$result9 = mysqli_query($connect,$query9);

        }
        else{
        $newbalance = $initialp + $balance;
$query8 = "UPDATE members_receiving SET balance = '$newbalance' WHERE user_id = $first_id ";
$result8 = mysqli_query($connect,$query8);
$result6 = mysqli_query($connect,$query6);
        $row3 = mysqli_fetch_assoc($result6);
        $balance = $row3['balance'];
if($balance == $userwithdrawal){
$query7 = "UPDATE account SET status = '1' WHERE user_id = $first_id ";            
$result7 = mysqli_query($connect,$query7);
$query9 = "UPDATE members_receiving SET status = '1' WHERE user_id = $first_id ";            
$result9 = mysqli_query($connect,$query9);
//$result3 = mysqli_query($connect,$query3);
//$result2 = mysqli_query($connect,$query2);
        }      

        }
        ?>

I’m not sure what you mean by “but it only runs it once” - your code only runs through once, there are no loops in it. Can you expand on the question please?

You’re running a lot of queries there, but you’re not checking whether any of them actually execute or give errors. You’re also not sanitising the data, presumably you’re sure the sanitising code isn’t causing the problem and have stripped that out for the purposes of posting on here. If that’s the case, it might be worth putting back in case there’s a typo you haven’t spotted.

Where does the value of $first_id come from? Is it correct that you don’t do anything with $query, the insert query?

1st check is your 1st query is being executed or not.
2nd thing is that you code vulnerable to SQL injections try to correct them too

You’ll also want to be looking at the use of transactions in case a query fails as you need all the queries to run ok

thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.