Allenph9 Posted February 24, 2012 Share Posted February 24, 2012 the strange thing is...I have the exact same script on another part of my page and it works! the only thing that changed are the variable names and the path (which ive checked 27000 times) What this should do is check if you have a signature in the external file and if you do and you fill out the form correctly then it replaces your old signature with your new one. and if you dont have a signature already and filled out the form correctly then it should write your signature to the file...for some reason this isnt working after checking and rechecking...i need a second pair of eyes. Help please! if (isset($_POST['change_submit2'])) { if (($_SESSION['logged_in'] == '1') && ($signature_test != '1') && ($_POST['change_box2'] == 'CHANGE') && ($invalid_character_test != '1') && ($invalid_character_test1 != '1')) { $fh1 = fopen($users_signatures_path, 'r+'); fwrite($fh1, $sig_front); frwrite($fh1, $_POST['signature']); fwrite($fh1, $sig_back); fwrite($fh1, ' '); flose($fh1); echo 'You have succesfully created a signature!'; } elseif (($_SESSION['logged_in'] == '1') && ($signature_test == '1') && ($_POST['change_box2'] == 'CHANGE') && ($invalid_character_test != '1') && ($invalid_character_test1 != '1')) { $users_signatures_path1 = "../../users/users_signatures.txt"; $fh1 = fopen($users_signatures_path1, 'r+'); $read_fh1 = fread($_fh1, filesize($users_signatures_path1)); $the_new_sig = str_replace($mcurrent_sig, $mnew_sig, $read_fh1); fclose($fh1); $fh1 = fopen($users_signatures_path1, 'r+'); fwrite($fh1, $the_new_sig); fclose($fh1); echo $mnew_sig; echo 'Your signature has been succesfully changed!'; } elseif ($_SESSION['logged_in'] != '1') { echo 'You need to be logged in!'; } elseif ($_POST['change_box2'] != 'CHANGE') { echo 'You must fill in the "CHANGE" box!'; } elseif ($invalid_character_test == '1') { echo 'Contains illegal characters!'; } elseif ($invalid_character_test1 == '1') { echo 'Contains illegal characters!'; } } Quote Link to comment https://forums.phpfreaks.com/topic/257691-this-str_replace-for-an-external-file-isnt-working/ Share on other sites More sharing options...
AyKay47 Posted February 24, 2012 Share Posted February 24, 2012 in the fread() call, you have the handle set to $_fh1, when it should be $fh1. You should always debug your code, that way little things like this are much easier to spot. Quote Link to comment https://forums.phpfreaks.com/topic/257691-this-str_replace-for-an-external-file-isnt-working/#findComment-1320817 Share on other sites More sharing options...
Allenph9 Posted February 24, 2012 Author Share Posted February 24, 2012 Thanks im sorry for posting something so stupid but i was about to blow my brains out! lol ty Quote Link to comment https://forums.phpfreaks.com/topic/257691-this-str_replace-for-an-external-file-isnt-working/#findComment-1320903 Share on other sites More sharing options...
Shadowing Posted February 25, 2012 Share Posted February 25, 2012 Hey AyKay47 what do you mean by debuging it. do you mean by using this ini_set("display_errors", "1");error_reporting(-1); I just used this just now for the first time. so not sure what all it really displays, but im assuming it displays any errors and even if you start a variable out with _ how does everyone handle this. Should i just keep this on every page so its always active? Is that what most people do? Quote Link to comment https://forums.phpfreaks.com/topic/257691-this-str_replace-for-an-external-file-isnt-working/#findComment-1321089 Share on other sites More sharing options...
scootstah Posted February 25, 2012 Share Posted February 25, 2012 Hey AyKay47 what do you mean by debuging it. do you mean by using this ini_set("display_errors", "1");error_reporting(-1); I just used this just now for the first time. so not sure what all it really displays, but im assuming it displays any errors and even if you start a variable out with _ Starting a variable with _ is completely valid. The only reason it didn't work in this case is because he set the handle to $fh1, and instead used $_fh1. Quote Link to comment https://forums.phpfreaks.com/topic/257691-this-str_replace-for-an-external-file-isnt-working/#findComment-1321091 Share on other sites More sharing options...
Shadowing Posted February 25, 2012 Share Posted February 25, 2012 Scootstah is the normal thing to do is to attached the following to a page that is required on all my pages? cause i just attached this to my page that connects me to my database and i got hit with 3 Notices. ini_set("display_errors", "1");error_reporting(-1); Quote Link to comment https://forums.phpfreaks.com/topic/257691-this-str_replace-for-an-external-file-isnt-working/#findComment-1321094 Share on other sites More sharing options...
PFMaBiSmAd Posted February 25, 2012 Share Posted February 25, 2012 @Shadowing, You should have error_reporting set to E_ALL (or even better a -1) and display_errors set to ON in your master php.ini on your development system, so that you don't need to remember to put anything into your files or remember to remove it later. Also, by putting these setting into your master php.ini, fatal parse errors in your main file will also be reported and displayed. Putting those settings in your main file won't show fatal parse errors (in your main file, but do show them for any included file) because your code never runs when there is a parse error, so that settings due to lines of code never take effect. Quote Link to comment https://forums.phpfreaks.com/topic/257691-this-str_replace-for-an-external-file-isnt-working/#findComment-1321095 Share on other sites More sharing options...
Shadowing Posted February 25, 2012 Share Posted February 25, 2012 yah i do have errors set to on but they apparently didnt make me aware of undefined index's. Notice: Undefined index: offense_level_points in C:\Software\XAMPP\xampp\htdocs\stargate\Users\battle.php on line 34 thats going to help me find errors much easier and makes things faster when there is a problem. i think i have mine set to E_ALL atm going to go check. if so wonder why it wasnt showing me these undefined index errors Quote Link to comment https://forums.phpfreaks.com/topic/257691-this-str_replace-for-an-external-file-isnt-working/#findComment-1321101 Share on other sites More sharing options...
Shadowing Posted February 25, 2012 Share Posted February 25, 2012 It also didnt make me aware of this notice too Notice: A session had already been started Quote Link to comment https://forums.phpfreaks.com/topic/257691-this-str_replace-for-an-external-file-isnt-working/#findComment-1321102 Share on other sites More sharing options...
PFMaBiSmAd Posted February 25, 2012 Share Posted February 25, 2012 You should probably start your own thread for your series of questions. The problem causing each error message you are getting should be fixed so that you only get errors from actual problems so that you can find and fix real problems in your code. The reporting and display/logging of the error message is only the last step in the error response code that php executes EVERY time it detects an error on a page, every time that page gets requested. Quote Link to comment https://forums.phpfreaks.com/topic/257691-this-str_replace-for-an-external-file-isnt-working/#findComment-1321105 Share on other sites More sharing options...
Shadowing Posted February 25, 2012 Share Posted February 25, 2012 I think im good now. I understand it shows a entire list of differant things i can set error reporting too. I currently have it set to E_ALL & ~E_NOTICE. i dont see anything in the constants talking about -1 though. but now i know why it wasnt showing me notices cause E notice means it doesnt show notices lol thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/257691-this-str_replace-for-an-external-file-isnt-working/#findComment-1321107 Share on other sites More sharing options...
AyKay47 Posted February 25, 2012 Share Posted February 25, 2012 Hey AyKay47 what do you mean by debuging it. do you mean by using this ini_set("display_errors", "1");error_reporting(-1); I just used this just now for the first time. so not sure what all it really displays, but im assuming it displays any errors and even if you start a variable out with _ how does everyone handle this. Should i just keep this on every page so its always active? Is that what most people do? yes, follow what PFM said. In this case, if the OP had the error settings correct, he should have received an "undefined variable" error and an invalid handle error. Quote Link to comment https://forums.phpfreaks.com/topic/257691-this-str_replace-for-an-external-file-isnt-working/#findComment-1321131 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.