techker Posted October 7, 2019 Author Share Posted October 7, 2019 That works great..love your php style...not there yet...lol Quote Link to comment https://forums.phpfreaks.com/topic/309337-updating-table-with-for-loop/page/2/#findComment-1570435 Share on other sites More sharing options...
Barand Posted October 7, 2019 Share Posted October 7, 2019 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 … As you are updating data your form method should be POST and not GET strip_tags hasn't been required since magic_quotes were deprecated decades ago mysqli_real_escape_string is not used with prepared queries, Quote Link to comment https://forums.phpfreaks.com/topic/309337-updating-table-with-for-loop/page/2/#findComment-1570436 Share on other sites More sharing options...
Psycho Posted October 8, 2019 Share Posted October 8, 2019 (edited) 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); }else{ 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 October 8, 2019 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/309337-updating-table-with-for-loop/page/2/#findComment-1570449 Share on other sites More sharing options...
Barand Posted October 8, 2019 Share Posted October 8, 2019 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. mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $mydb = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); Quote Link to comment https://forums.phpfreaks.com/topic/309337-updating-table-with-for-loop/page/2/#findComment-1570450 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.