Jump to content

garyed

Members
  • Posts

    176
  • Joined

  • Last visited

Everything posted by garyed

  1. I thought about marking this thread as solved but I would be lying because I still am in the process of trying to solve all my errors. It seems rather ridiculous that one version of php will work with errors turned off while a newer version won't. I've already fixed over a hundred errors in php 8.x & things are looking worse than before I started. I can go back to php 7.4 & the program will work flawlessly. If it's not an undefined variable error, it's a string & int error or something else. It's frustrating because I spent years writing this program & just learned as I was going along. It's been working fine for 10 years & now the upgrade to php 8.x has killed it. I've got over 1000 variables I'm dealing with & hundreds of calculations so it's not a simple task.
  2. I appreciate the help. It's a lot of good information that I've got to process. I'm a little slow at times but i'll eventually get it.
  3. I'm tried your code but it still doesn't insert the session data in the fileds & dropdown when I leave & return. I'm not sure what I'm missing but the only thing I know to do is to add something similar to what I already have to get it to work.
  4. Thanks, I'll check into "heredocs". I never even heard of it before you just mentioned it. I'm also going to study your code until I understand it better. What I'm really trying to do is to havel all 50 states in the dropdown menu from a MYSQL database & put whichever one is selected into the session. Then change the page to perform another task then return to the page & have the state from the session be already selected upon return.
  5. It seems to work fine but I would like to hear what you guys who are more versed in php think. In my previous post I was trying find a way to hide the errors but I really want to get things right this time. This is a sample code that I'm using as a test but on my site I'm going to be pulling my variables off a database & using a while loop to fill in all 50 states. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); session_start(); // Starts session & uses function to keep data */ function get_value($var) { // this will check your session if it's not empty and you send an empty post if ($_POST[$var]!="" || (!empty($_SESSION[$var]) && $_POST[$var] === '')) { $_SESSION[$var]=$_POST[$var]; } if (isset($_SESSION[$var])){ return $_SESSION[$var];} else{ return $_POST[$var];} } if(!isset($_POST['submitter'])) {$_POST['submitter']="anything"; } // initialize to avoid Undefined array key error ?> <form name="test" action="" method="post"> <input type="text" style="width:255px;" name="owner" value="<?php if(isset($_POST['owner'])) {echo get_value('owner'); } else { if(isset($_SESSION['owner'])){ echo $_SESSION['owner'];} } ?>"> <br> <input type="text" style="width:255px;" name="renter" value="<?php if(isset($_POST['renter'])) {echo get_value('renter');}else { if(isset($_SESSION['renter'])){ echo $_SESSION['renter'];} } ?>"> <br> <select name="state" > <option value=""> select state </option> <?php $state1="Maine" ; $state2="Texas" ; ?> <option value="<?php echo $state1; ?>" <?php if(isset($_POST['state'])) { if(get_value('state') == $state1) { echo 'selected="selected"'; } } else { if(isset($_SESSION['state'])){ if ($_SESSION['state']==$state1) { echo 'selected="selected"'; } } } ?> > Maine </option> <option value="<?php echo $state2; ?>" <?php if(isset($_POST['state'])) {if (get_value('state')==$state2) { echo 'selected="selected"'; }} else { if(isset($_SESSION['state'])){ if ($_SESSION['state']==$state2) { echo 'selected="selected"'; } } } ?> > Texas </option> </select> <br> <br> <br> <input type="submit" value="submit"> &nbsp; &nbsp; <input name="submitter" type="submit" value="clear session"><br> </form> <?php if ($_POST['submitter']=="clear session") { echo $_POST['submitter']."<br>"; session_destroy(); }; print_r($_SESSION); ?>
  6. This seems like a hard way to do it but it looks like it works OK. Any suggestions ? value="<?php if(isset($_POST['owner'])) {echo get_value('owner'); } else { if(isset($_SESSION['owner'])){ echo $_SESSION['owner'];} } ?> "
  7. Thanks for the ideas, I can get rid of the errors by initiating $_POST['submitter'] & testing if $_POST['owner'] is initiated but then my session variable gets lost when leaving the page. Keeping the session variable is where my problem is. if(!isset($_POST['submitter'])) {$_POST['submitter']="hello"; } // insert before using $_POST['submitter'] // change value of input to this: value="<?php if(isset($_POST['owner'])) {echo get_value('owner'); }?> " The session variable is really not lost but it doesn't appear in the input field after leaving the page & coming back to it which is the problem especially if I'm dealing with a lot of inputs.
  8. Follow up with code: I didn't know if i should post this as a separate thread or not since the question is about fixing errors instead of covering them up. I'm trying to figure out how to get rid of the errors in this code because it's very similar to my site with a lot more inputs & I'm stumped. <!DOCTYPE html> <html> <head> </head> <body> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); session_start(); // Starts session & uses function to keep data */ function get_value($var) { // this will check your session if it's not empty and you send an empty post if ($_POST[$var]!="" || (!empty($_SESSION[$var]) && $_POST[$var] === '')) { $_SESSION[$var]=$_POST[$var]; } if (isset($_SESSION[$var])){ return $_SESSION[$var];}else{ return $_POST[$var];} } ?> <form name="test" action="" method="post"> <input type="text" style="width:255px;" name="owner" value="<?php echo get_value('owner'); ?> "> <br> <input type="submit" value="submit"> &nbsp; &nbsp; <input name="submitter" type="submit" value="clear session"><br> </form> <?php if ($_POST['submitter']=="clear session") { session_destroy(); } print_r($_SESSION); ?> </body> </html>
  9. Thanks for the encouragement, I know I'll get it done but it's just going to take time. I just do this as a hobby & the code on the site in question I wrote about 10 years ago. When you don't do it everyday, it's easy to forget how you did something that far back. I was just hoping I could fool php8.0 like i did 7.2 for a little while longer
  10. I understand what you're saying & I definitely want to straighten the code out & get rid of all the errors properly. I had the same problem about a year ago,when my webhost upgraded the php version to 7.4. I turned off the errors to keep the site up & running & started trying to fix things but I just gave up after a couple days. I got lazy since everything was still working & just forgot about doing anything about the errors. I should have fixed things while I had the time but now I'm paying the price for procrastinating.
  11. Not that I know of but that doesn't mean they are not there. I wouldn't even know where to look for them.
  12. Yes, since my site works under php 7.4 by turning off errors, is there a stronger way to turn off errors that might allow it to still work under php 8.0?
  13. I've got about a thousand of them : Then it gets even worse because all of those errors can go away by turning off errors but then when you go further into the site it will lock up completely & go blank. If I keep the errors turned on then I can't get to the part of the site where it locks up to see what error is causing the lockup. It's actually a very involved load calculation sight with a lot of inputs & a lot of people use it & I want to keep it going.
  14. I have tried investigating but have come up dry. Error 500 is pretty generic & doesn't give any specific details & I don't know where to start looking. Even if it's a permission issue I still don't know what to do to fix it. I've tried a couple edits on config files the other day but they didn't work & I can't even remember what I tried now. My next step was to copy all the phpmyadmin config files while I have 7.2 running & then compare them with the config files with 8.1 running. That's probably a waste of time but I figured before I do that I would post here & see if anyone was familiar with the problem.
  15. I have two versions of php (7.2 & 8.1) installed along with Apache server on Ubuntu 18.04 that I can switch back & forth from. If I enable 7.2, Phpmyadmin works fine but if I enable 8.1 & try to open Phpmyadmin, then I get the " HTTP ERROR 500" along with "localhost is currently unable to handle this request" message. Any ideas?
  16. My webhost has upgraded from php 7.4 to 8.0 & I have quite a few pages on different sites that just will not work with the upgrade. I've been masking all my errors in 7.4 by using "display_errors = Off " in my php.ini & that's done the job until now but the pages will not work in 8.0 I guess all the bad code is catching up to me but we're talking about thousands of lines of code that I wrote years ago & it's going to take a long time to correct. I don't want my sites to be down so I'm paying a monthly fee to my webhost (1and1) to keep supporting php7.4 & I don't know how long that will last. I've also tried putting this in my pages to no avail: error_reporting(E_ALL ^ E_NOTICE); I'm just trying to buy time until I can get things right so I'm wondering if anyone has any ideas for me in the mean time. I do test all my new code for errors as I'm going along but all my old code was never tested for errors. This reminds me of what I was told about people who use computers a while back. There are two types, those who backup & those who will backup
  17. If I use either of these statements, the result is the same. Joe has ([\d.]+) large apples Joe has (\d.+) large apples It doesn't seem to matter whether I put the square brackets in or not. Are those brackets are there for a reason beyond the scope of the usage in this particular statement?
  18. I have been learning & experimenting with regular expressions as you suggested & was just curious as to why you use the square brackets inside the curly brackets. I've found that whether I use the square brackets or not, the result is the same. Is it optional or is there a specific reason why they should be used?
  19. My bad, I was trying to make my example simple to get across what I was trying to do & never even considered that the answer could be different if there were decimals involved. Hopefully I'll be a little more thorough next time, but I really appreciate the help from you guys here.
  20. Thank you, That was what I needed & I definitely do need to spend a lot more time learning those expressions. I know it's wrong but I usually learn backwards & try to find a solution to a problem when i run into one instead of learning the basics first.
  21. I appreciate your help but I don't think that solves the problem. I just need to find one specific unknown number in a specific string out of a huge string with multiple numbers. The example of "Joe has (x) large apples" would be the line I'm searching for in like 1,000 lines of code with multiple numbers where (x) is an unknown number. Mac_gyver's solution worked because it took the specific string where the unknown number was inside it & pulled it out. The only problem is that it would only pull out a whole number & the decimal part was lost. Your solution would come up with too many numbers that I would still have to find a way to narrow it down to the specific string that holds the correct number.
  22. Your solution would work if I knew the number in the string but the problem is that don't know the number that will be in the the string that I'm searching for. Basically I'm searching for the number inside a specific string that is inside a larger string.
  23. Well I thought everything was solved but i found that (\d+) only works on whole numbers. I didn't think it would matter if the number had a few decimal points but I was obviously wrong. If there is a decimal like 5.5 or 5.25 then it will only pick up the 5 & not the rest of the number.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.