ajetrumpet Posted December 28, 2019 Share Posted December 28, 2019 can someone give me a push here? I've tried "file_put_contents" and "fputs" and neither one works for me. I'm running PHP on an IIS server and a windows hosting plan. PHP version is 7.3.1 I believe. here is my code: if ($validation = "true") { file_put_contents("ValidationsRedeemed.txt", $validationKey . "|", FILE_APPEND); //$handle = fopen("ValidationsRedeemed.txt", "a"); //fwrite($handle, $validationKey . "|"); //fclose ($handle); } else { //user entered a product key that is not recognized. tell them to try again. echo "<script>alert('The product key entered is not valid.'+'\\n\\n'+'Please try again.'); window.location.href='test.php';</script>"; } thanks! Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/ Share on other sites More sharing options...
gw1500se Posted December 28, 2019 Share Posted December 28, 2019 What is the error you are getting? Is error reporting enabled? Did you output the data to make sure it is what you expect? Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572918 Share on other sites More sharing options...
ajetrumpet Posted December 28, 2019 Author Share Posted December 28, 2019 I tried this, gw: if ($validation == "true") { //file_put_contents("ValidationsRedeemed.txt", $validationKey . "|", FILE_APPEND); $handle = fopen("ValidationsRedeemed.txt", "w"); echo fputs($handle, $validationKey . "|"); fclose ($handle); } else { //user entered a product key that is not recognized. tell them to try again. echo "<script>alert('The product key entered is not valid.'+'\\n\\n'+'Please try again.'); window.location.href='test.php';</script>"; } I put this line at the top of the php script page: error_reporting(E_ALL); when I run the script, I get a blank page. there is no error log file on the server in the directory either. ???? Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572920 Share on other sites More sharing options...
Barand Posted December 28, 2019 Share Posted December 28, 2019 If you have a syntax error elsewhere in the script (and it sounds like you have) then it will not run at all, so your error reporting statement cannot be executed. Error reporting needs to be defined in the php.ini file. Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572921 Share on other sites More sharing options...
ajetrumpet Posted December 28, 2019 Author Share Posted December 28, 2019 (edited) Berand, I dont' believe I can access the php.ini file. i remember a discussion between us about this a while back. Do you remember that? Here is what my setting is in the phpinfo() page on my domain: Quote display_errors Off Off however, another line of the file says this: Quote log_errors On On Edited December 28, 2019 by ajetrumpet Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572922 Share on other sites More sharing options...
ginerjm Posted December 28, 2019 Share Posted December 28, 2019 One problem might be the very first line of your post. That "if" statement is incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572923 Share on other sites More sharing options...
ajetrumpet Posted December 28, 2019 Author Share Posted December 28, 2019 (edited) 59 minutes ago, ginerjm said: One problem might be the very first line of your post. That "if" statement is incorrect. what's wrong with it? is it spose to be 2 = signs or 3? am I spose to check a boolean without the string in quotes? I tried it with 2 = signs even, and that didn't work either. sorry, I get confused sometimes with the difference between 2 and 3 = signs and the comparisons they're spose to make! Berand, I don't have an ini file yet on this hosting plan. I will create one, which is ".user.ini", spose to be put in the root folder. I'll get to it when I have time. I'll let you know how it goes. thanks. Edited December 28, 2019 by ajetrumpet Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572929 Share on other sites More sharing options...
Barand Posted December 28, 2019 Share Posted December 28, 2019 A single = is an assignment operator, so if ($validation = "true") assigns the string "true" to $validation. In your second code example you are checking equality correctly but your are checking if it is equal to the string value "true". This will suffice... if ($validation) { as this means "if validation is true" Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572931 Share on other sites More sharing options...
NotSunfighter Posted December 28, 2019 Share Posted December 28, 2019 (edited) What comes to my mind is this: if ($validation == "true") { Notice the double equal signs. This is saying the loop works if the variable $validation is the word TRUE not that $validation is true. About what the same as Barand just posted. BTW - I live in Urbandale, Ia Edited December 28, 2019 by NotSunfighter Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572932 Share on other sites More sharing options...
ginerjm Posted December 28, 2019 Share Posted December 28, 2019 Your new if is asking if the variable contains the string "true". It is not checking if the value of it is a boolean value. Do you not know the difference between a string value and a boolean one? Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572938 Share on other sites More sharing options...
gw1500se Posted December 28, 2019 Share Posted December 28, 2019 (edited) If you are getting a blank page then that means neither 'echo' is working and the code may be failing somewhere else. However, if the 'fputs' is outputting invalid HTML then that may also appear as a blank page. When that blank page is up, show the source to see if anything is there at all. Edited December 28, 2019 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572942 Share on other sites More sharing options...
ginerjm Posted December 28, 2019 Share Posted December 28, 2019 If the last set of code is what you are running, what exactly do you expect it to be showing you? And why is your 'fputs' call embedded in an 'echo' statement? Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572946 Share on other sites More sharing options...
maxxd Posted December 28, 2019 Share Posted December 28, 2019 If you're attempting to append data to the text file, you need to open the stream with 'a' or 'a+' mode - 'w' will truncate the file. Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572949 Share on other sites More sharing options...
ajetrumpet Posted December 28, 2019 Author Share Posted December 28, 2019 (edited) ok guys, I sent the deployable to the requester with a workaround, so this is no longer relevant, however I will respond to all you guys: => yes i was trying to APPEND. so I had that wrong as I was using "w". thanks! => 'fputs' was embedded inside an ECHO statement in an attempt to see the number of BYTES fputs throw into the text file. I got that debugging method from www.w3schools.com => I'm not sure what "showing the source" of the blank page would do for me. I'm not even sure what you mean by that. and how could 'fputs' output HTML? that doesn't make sense. isn't 'fputs' purpose to stream files, regardless if the process is "i" or "o"?? it's an I/O function, isn't it? => and YES, of course I know the difference between a freakin boolean and string! i've been doing this job for 12 years! 😃 => Berand, I really should have gone with your advice....if ($validation) { .....because it makes more sense. I just picked a string in the form of "true/false" because it came to mind first. no other reason. => NotSunFighter ------- you're not far from me. where do you work? would you be interested in connecting somehow? this whole thing was simply an illustration for someone who wanted to validate product registration by checking a product key against keys that were purchased. I used a combination of ms access, VBA code, HTML, CSS and PHP to accomplish the goal by sending the user to a webpage where they could validate their product by inputting their product key and then using PHP POST[] to do the work. I know it's not the easiest way to do it, as the same can be accomplished with javascript with less coding, but that's what I had in my knowledgebase from years ago so it was easy to send to the person quickly. It can easily be done in ms access as well. but I've always hated that program because every release is extremely buggy. and for good reason...MS makes no money with it so they obviously don't pay much attention to it's development. If I was MS, I wouldn't care either. Edited December 28, 2019 by ajetrumpet Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572953 Share on other sites More sharing options...
Barand Posted December 28, 2019 Share Posted December 28, 2019 Personally, I'd go with file_put_contents('filename', 'content', FILE_APPEND); So much easier than fopen(), fwrite(), fclose(). Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572954 Share on other sites More sharing options...
ajetrumpet Posted December 28, 2019 Author Share Posted December 28, 2019 you know Barand, I actually DID try that! and it resulted in the exact same thing I'm complaining about in this thread. I also got that from w3schools. Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572955 Share on other sites More sharing options...
Barand Posted December 29, 2019 Share Posted December 29, 2019 Does this simple script work? <?php echo file_put_contents("ValidationsRedeemed.txt", 'This is a test' . "|", FILE_APPEND); ?> (It should output 15 to the browser and add "This is a test|" to your file) Quote Link to comment https://forums.phpfreaks.com/topic/309756-help-with-appending-data-to-a-text-file/#findComment-1572957 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.