Jump to content

updating table with for loop


Recommended Posts

Are you saying that when you select "1" from the dropdown then $_GET['cr'] contains "2"

You don't show your <select> tag - can you confirm the name = 'cr' ?

It looks OK but check the source code of your form page to make sure the menu is built correctly.

Some general points …

  1. As you are updating data your form method should be POST and not GET
  2. strip_tags hasn't been required since magic_quotes were deprecated decades ago
  3. mysqli_real_escape_string is not used with prepared queries,
Link to comment
Share on other sites

You are executing the query TWICE. The part in the if() condition isn't checking the results of the first execution - it is executing the query a second time and the if condition is acting based upon the true/false response of that second execution.

$stmt = $DBcon->prepare("UPDATE Codes SET UserID = ? WHERE UserID = ? LIMIT ?");
$stmt->bind_param('iii', $subida, $userida, $cra);
$stmt->execute();  //FIRST EXECUTION

if(!$stmt->execute()) { //SECOND EXECUTION
    echo "Error: " . mysqli_error($DBcon);
    echo "Success adding user : $subida with : $cra  ";
		echo "<meta http-equiv=Refresh content=1;url=Subseller.php?success=1 >";

You can either execute ONCE within the if() condition or assign the result of the first execution to a variable and check the value of the variable in your if() condition

$stmt->bind_param('iii', $subida, $userida, $cra);
$result = $stmt->execute();

if(!$result) {
    echo "Error: " . mysqli_error($DBcon);


Edited by Psycho
Link to comment
Share on other sites

Shame on me for missing that!

@techker To save having to test if every mysqli function call worked or not, tell it to throw an exception automatically. It keeps your code a lot cleaner. Call mysqli_report() before you connect to the db.


 $mydb = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.