Bickey Posted January 12, 2011 Share Posted January 12, 2011 Why won't this code work when register_globals is turned off (works fine when register_globals is on though). <?php $link = mysql_connect("localhost","un","pw"); mysql_select_db("the_db"); $username = $_POST['usernamex']; $surname = $_POST['surname']; $email = $_POST['email']; $result =sprintf("SELECT * FROM tbl WHERE username ='%s' || email = '%s'", mysql_real_escape_string($username), mysql_real_escape_string($email)); $resultfin = mysql_query($result); if (mysql_num_rows ($resultfin) > 0){ $register = "Retry."; echo($register); } else { $go =sprintf("INSERT INTO tbl (username, email, surname) VALUES ('%s', '%s', '%s'", mysql_real_escape_string($username), mysql_real_escape_string($email), mysql_real_escape_string($surname)); $resultg = mysql_query($go); $register = "Successful."; echo($register); } ?> Thanks, Bickey. Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/ Share on other sites More sharing options...
trq Posted January 12, 2011 Share Posted January 12, 2011 There is nothing in that code that should be effected by register_globals which by the way should *NEVER* be enabled. Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158277 Share on other sites More sharing options...
Bickey Posted January 12, 2011 Author Share Posted January 12, 2011 Strange. When I turn register_globals off using php.ini EZConfig (in phpMyAdmin) the code doesn't function. Any ideas on why is this happening? Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158280 Share on other sites More sharing options...
trq Posted January 12, 2011 Share Posted January 12, 2011 Any ideas on why is this happening? Pretty sure I already answered that. Have you tried debugging your code? I don't see any. Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158283 Share on other sites More sharing options...
lastkarrde Posted January 12, 2011 Share Posted January 12, 2011 which by the way should *NEVER* be enabled. cannot emphasis this enough. Any ideas on why is this happening? The code looks fine. Try enabling logging and errors? EDIT: Is this line intentional? $username = $_POST['usernamex']; should it be $_POST['username'] ? Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158284 Share on other sites More sharing options...
Bickey Posted January 12, 2011 Author Share Posted January 12, 2011 What surprises me is when register_globals is on the code does what it's supposed to do but having the exact same code and when I turn register_globals off the code inserts blank fields in the database. Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158287 Share on other sites More sharing options...
Bickey Posted January 12, 2011 Author Share Posted January 12, 2011 is there any other settings which I adjusted might be forcing to stop this code functioning? Truly appreciate your support. Set as ON engine On short_open_tag On allow_call_time_pass_reference On display_errors On file_uploads On allow_url_fopen On allow_url_include On Set as OFF asp_tags Off output_buffering Off zlib.output_compression Off implicit_flush Off safe_mode Off safe_mode_gid Off expose_php Off display_startup_errors Off log_errors Off ignore_repeated_errors Off ignore_repeated_source Off report_memleaks Off track_errors Off register_globals Off register_argc_argv Off magic_quotes_gpc Off magic_quotes_runtime Off magic_quotes_sybase Off sql.safe_mode Off mysql.allow_persistent Off mysql.trace_mode Off Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158292 Share on other sites More sharing options...
Bickey Posted January 12, 2011 Author Share Posted January 12, 2011 Anyone? any thoughts please. Thanks. Bickey. Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158306 Share on other sites More sharing options...
PFMaBiSmAd Posted January 12, 2011 Share Posted January 12, 2011 There's probably something in your form that is affected by register_globals. As thorpe already asked, what debugging have you done to find out exactly at what point your code and data has the expected values and exactly at what point they don't. I can guarantee that the problem is somewhere between those two points. Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158318 Share on other sites More sharing options...
Pikachu2000 Posted January 12, 2011 Share Posted January 12, 2011 EDIT: Is this line intentional? $username = $_POST['usernamex']; should it be $_POST['username'] ? Have you addressed this? Is there a actually form field with the name="usnernamex" attribute, or is that a typo? Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158367 Share on other sites More sharing options...
Bickey Posted January 13, 2011 Author Share Posted January 13, 2011 sorry... that was a typo. it is $username = $_POST['username']; but the script is not sending the data to the database, it just inserts all fields as blank. Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158712 Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2011 Share Posted January 13, 2011 Someone already suggested the problem could be your form. Posting all the code that reproduces the problem would be the quickest way of getting a solution. We could see exactly what you are doing that is being affected by the register_globals setting. Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158723 Share on other sites More sharing options...
Bickey Posted January 13, 2011 Author Share Posted January 13, 2011 Thanks. This is the exact script which is in my php file. The data is being to this file to pass them over to the mysql database. <?php $link = mysql_connect("localhost","un","pw"); mysql_select_db("the_db"); $result =sprintf("SELECT * FROM tbl WHERE username ='%s' || email = '%s'", mysql_real_escape_string($username), mysql_real_escape_string($email)); $resultfin = mysql_query($result); if (mysql_num_rows ($resultfin) > 0){ $register = "Retry."; echo($register); } else { $go =sprintf("INSERT INTO itc_applicants (username, password, surname, firstname, nickname, company, street, suburb, postal, phone, email, product, status, id) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s'", mysql_real_escape_string($username), mysql_real_escape_string($watchword), mysql_real_escape_string($surname), mysql_real_escape_string($firstname), mysql_real_escape_string($nickname), mysql_real_escape_string($company), mysql_real_escape_string($street), mysql_real_escape_string($suburb), mysql_real_escape_string($postal), mysql_real_escape_string($phone), mysql_real_escape_string($email), mysql_real_escape_string($product), mysql_real_escape_string($status), mysql_real_escape_string($id)); $resultg = mysql_query($go); $register = "Successful."; echo($register); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158735 Share on other sites More sharing options...
Pikachu2000 Posted January 13, 2011 Share Posted January 13, 2011 Post the form as well, plz Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158736 Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2011 Share Posted January 13, 2011 That's not the code you posted at the start of the thread. Seriously, how can anyone help you with what YOUR code is doing unless you post the actual code you need help with. Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158743 Share on other sites More sharing options...
Bickey Posted January 13, 2011 Author Share Posted January 13, 2011 yes... I just stripped some thinking the issue is elsewhere. Because the code works perfectly and only when register_globals is turned off it inserts blank data to the database. The data is being sent from a flash website. Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158748 Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2011 Share Posted January 13, 2011 The last code you posted is not referencing the $_POST variables where the actual form values are at, so of course it doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/224160-not-responding-when-register_globals-is-turned-off/#findComment-1158948 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.