SalientAnimal Posted January 27, 2014 Share Posted January 27, 2014 (edited) Hi there, can anyone tell me why this query would not run? <?php include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; include_once '../includes/session_management.php'; $error_msg = ""; // create string of queries separated by ; $query = "UPDATE members SET level = $level WHERE user_id = ?"; var_dump($_POST);exit; $query .= "INSERT INTO members_info ( id , fname , known_as , lname , gender , race , start_date , department , level , msisdn , dob , details , emergency_contact , emergency_msisdn ) VALUES ( '$user_id' , '$fname' , '$known_as' , '$lname' , '$gender' , '$race' , '$start_date' , '$department' , '$level' , '$msisdn' , '$dob' , '$details' , '$emergency_contact' , '$emergency_msisdn' );"; // execute query - $result is false if the first query failed $result = mysqli_multi_query($mysqli, $query); if ($result) { do { // grab the result of the next query if (($result = mysqli_store_result($mysqli)) === false && mysqli_error($mysqli) != '') { echo "Query failed: " . mysqli_error($mysqli); } } while (mysqli_more_results($mysqli) && mysqli_next_result($mysqli)); // while there are more results { //var_dump($_POST);exit; header('Location: ../error.php?err=Registration failure: INSERT'); exit; } include "../success.html"; exit; } else { echo "Update Query Failed..." . mysqli_error($mysqli); } In IE it just seems to keep running and in Firefox I get a message saying "Firefox has detected that the server is redirecting the request for this address in a way that will never complete." Edited January 27, 2014 by SalientAnimal Quote Link to comment Share on other sites More sharing options...
0xMatt Posted January 27, 2014 Share Posted January 27, 2014 (edited) Of course you are getting that error, you are redirecting inside your while loop. As for the query failure, you'll need to post the error message supplied. Edited January 27, 2014 by 0xMatt Quote Link to comment Share on other sites More sharing options...
SalientAnimal Posted January 27, 2014 Author Share Posted January 27, 2014 (edited) I removed the redirect from my code but I still get the same error. IE does not return any error, it just hangs in a continuous looping saying 'Waiting for localhost' In Firefox, I immediately go to a page that says " The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete." What I'm not sure about though, is if my page might be using the old outdate "post" page because when I hit submit I have the incorrect post page appearing in my address bar. To try fix this, I have tried restarting the server, clearing my browser cache, as well as restarting, apache, and MySQL. But it still runs the incorrect post page. Edited January 27, 2014 by SalientAnimal Quote Link to comment Share on other sites More sharing options...
0xMatt Posted January 27, 2014 Share Posted January 27, 2014 You cannot receive a redirect error if the page isn't even trying to redirect or send with a 3xx. Double check and make sure you modified and saved the correct file and cleared your browsers cache just in case. Quote Link to comment Share on other sites More sharing options...
SalientAnimal Posted January 27, 2014 Author Share Posted January 27, 2014 I have cleared browser history twice now, closed everything. And reopened the files, made sure the correct ones were edited etc. I even viewed the source code and the correct source code is showing. But like I say, with it directing to the incorrect page, I don't even know if the page is being processed correctly, and if the code is correct or not. Quote Link to comment Share on other sites More sharing options...
SalientAnimal Posted January 27, 2014 Author Share Posted January 27, 2014 (edited) Ok so I feel like a bit of a fool not remmebering this earlier, but had a section where I protect my pages, and this page was not accessilbe which is why it kept redirecting to the incorect location. The problem though is I'm get the underfined variable error message. I have done var_dump($_POST);exit; and confirmed that the information is getting posted. I have also updaed my code in the submit for to <?php include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; sec_session_start(); if (login_check($mysqli) == true) { $logged = 'in'; } $error_msg = ""; $username = $_SESSION['username']; $email = $_SESSION['email']; $id = $_SESSION['user_id']; //var_dump(login_check($mysqli)); //var_dump($_SESSION); exit; //var_dump($_POST);exit; $query = "UPDATE members SET level = '$POST_[level]' WHERE user_id = ?"; $query .= "INSERT INTO members_info ( id , fname , known_as , lname , gender , race , start_date , department , level , msisdn , dob , details , emergency_contact , emergency_msisdn ) VALUES ( ('$_POST[user_id]' , '$_POST[fname]' , '$_POST[known_as]' , '$_POST[lname]' , '$_POST[gender]' , '$_POST[race]' , '$_POST[start_date]' , '$_POST[department]' , '$_POST[level]' , '$_POST[msisdn]' , '$_POST[dob]' , '$_POST[details]' , '$_POST[emergency_contact]' , '$_POST[emergency_msisdn]' );"; // execute query - $result is false if the first query failed $result = mysqli_multi_query($mysqli, $query); if ($result) { do { // grab the result of the next query if (($result = mysqli_store_result($mysqli)) === false && mysqli_error($mysqli) != '') { echo "Query failed: " . mysqli_error($mysqli); } } while (mysqli_more_results($mysqli) && mysqli_next_result($mysqli)); // while there are more results } else { echo "Update Query Failed..." . mysqli_error($mysqli); } Parse error: syntax error, unexpected '$result' (T_VARIABLE) in C:\Development_Tracker\htdocs\process\register.addinfo.php on line 65 Edited January 27, 2014 by SalientAnimal Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted January 27, 2014 Solution Share Posted January 27, 2014 you need to forget about using a multi query, for the following reasons - 1) when running queries you need to know which one is failing and why and for related queries, there's usually no point in running following queries after the point of a failure, they will likely fail for the same reason, 2) your first query is partly using prepared query syntax and it's putting raw user data into the query. there is no prepared multi query and you need to escape/cast external data to prevent query errors and to prevent sql injection. 3) the query statements must be separated by a ;. you don't have one after the first query. Quote Link to comment Share on other sites More sharing options...
SalientAnimal Posted January 27, 2014 Author Share Posted January 27, 2014 I managed to get this working. I was posting my update as you replied mac_gyver. The fix was largely the adding of a ; as you mentioned and some brackets had missing. Quote Link to comment 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.