Need Assistance Out of Date PHP Code

No, not in a file. You need to go into the files under c:\xampp\php and look for a FOLDER named pear.
Once you find that, you can add the include_path line at the top of any files that look for the Table.php file.
Where are you, if you do not mind? I am in VT, in the US and it is 1PM Saturday afternoon here.
Talk to you once you get back up!

I am in Queensland Australia, just gone 3am Sunday Morning here

Oh, nice ! I have helped several people from your area! I would love to visit there one day!
Well, get some sleep! I will check in on your later…

Ok, and thanks again so much for your help, guidance and assistance I really do appreciate it.

No problem! That is why we are on this site!

Just one point, on line 68 it says “require_once ‘HTML/Common.php’ ;” My limited code experience says it is pointing to a file called Common.php which is in a folder called HTML, there is no folder, that said, I did find a file called Common in the PEAR Folder.

Well, I will quickly explain INCLUDES. Most of the time they are external files that you have created or that have been added from a library. In PHP there are a ton of libraries that assist with things such as reading or writing to Excel files, PDF files and other things like that. Table.php and Common.php sound like they might have been used from PEAR, but, I am not sure. Hard to guess without seeing some of your code.

Now, with that said, you can change the require_once to pint at the other one in the PEAR folder and see if it works or not. Or, just comment it out for now. Using // at the beginning of the require_one line. That would dummy it out and then see if other errors appear. So, if that file is really needed, you will see other errors pop up if routines in that file are needed. Most likely they will be undefined-function errors or similar. I think you can just dummy them out for this first test.

Yes I did point both of them the where the respected files are, but then I got error after error Where I saw one error I quoted that out, then a new one quoted that out, did the same for about 10 times but kept getting more and more… I ended up undoing all the changes I made in the Table.PHP file. I will make a copy of it and rename the original, then go back through and make all the changes (wont wreck the original) It is referring to Tables, well yes my original design used Tables as I could not get the products to display in Divs etc (I assume it is going to tables as it has detected Tables in the pages… or I may be way off the mark… I am asking myself Why now… Why did I open this can of worms… Bed Time

Ha! Programming puzzles are just that! We will help you solve it all.

I suggest at some point you show us some of your code. Tomorrow once you get back up. Get some rest!

Hey Keith,

Also did Cert IV Web technologies due to the company I was working for wanting someone with web abilities to maintain a website etc.

Did mine in 2015 and yes the PHP being taught is completely out of date. Think they were using version 5.

So to clarify, the older approach to connecting to MySQL is outdated and simply don’t go there.

You have two options

mysqli - mainly aimed at procedural style of coding.

pdo - aimed at OOP as the database is pretty much treated as an object. pdo also has the advantage of connecting to multiple dbs, so if that is a requirement.

There’s a learning curve for both approaches, but nothing a couple of tutorials won’t resolve.

Strangely the only problem I ran into upgrading from a php5 site to 7 was something to do with arrays, can’t quite remember the issue.

Good luck.

Hi This site plays up a bit, quite often I try to log in, and I keep getting an error saying “You can’t Log In as KeithAus from that IP Address” I have tried to contact admin about this, but there have been no replies, it appears that I have to wait 24 hours after logging in/logging Out to actually be able to log back in again… Pain in the…

Anyway, I have been looking at the problems, In the "Table.php: file, I was getting error after error, and I just commented out all the errors, but, there are no “active” actions that have not been commented out, and while the basic page does open in full now, there are no items displayed at all but there are no errors either.

As for the code, I was going to ask if you would like me to zip the file and send it to you? If not I can just post a page or two here. WHEN it lets me log back in that is.

It is close to 11pm here so I wont be here for a lot longer, have a 4:30 start in the morning, I might just stay logged in if it lets me.

I leave mine logged in all the time. We have had several people having trouble logging in. I also tried to contact the owner, but, he has not responded to me either as yet. It all started happening after Microsoft did they big update. But, several people are using phones to access the site. So, I think it is something to do with the site’s server.

As far as zipping it up, if you do, send it in a private message. But, you should handle each error and fix them up one by one. If I do it for you, you will not learn anything. So, perhaps you should leave the table.php in place and just post the first error here. Copy it from the code showing the bad line and a few lines before and after the line throwing the error. Click on the QUOTE or PREFORMATTED tabs above the typing area and paste the code between them. You can look at the preview on the right to see how they will look once posted. And, get some sleep! I will check in later in my day to see what you posted. How’s the weather there, down-under! Ha!

Hi, the weather is ok here in Brisbane, clouding over, but we do need more rain as our combined Dam levels are at only 55%, so yeah a lot more rain needed. Unfortunately, we get rainfall but it is after the catchment areas, which is not good for long term.

Ok so I went back to the original “Table.php” File. First “Error/ Warning” is:

Warning: require_once(HTML/Common.php): failed to open stream: No such file or directory in C:\xampp\php\pear\Table.php on line 68

Fatal error: require_once(): Failed opening required ‘HTML/Common.php’ (include_path=‘C:\xampp\php\PEAR’) in C:\xampp\php\pear\Table.php on line 68

Ther is no Folder Called HTML, so no “Common.php” file. There are other “Common.php” files, BUT they are all different, so that is of no help. There is also a reference to a file on line 69 in Table.php to HTML/Table/Storage.php, which would also display an error. There is only one “Storage.php” file, but wether it is the right one, I cannot say.

Ok, and thanks for that. The changes between 5 and 7 were major and it is difficult too keep up unless you code every day I think. But guess the changes are likely for the better…

Well, Keith, missing files mean that you are either pointing at the wrong place or you are missing files.
The problem is your current setup. I will guess that your current Xampp layout is different than your older one you had in class. OR, they had extra files that you did not copy when you made your backup.

Why don’t you zip up what you have and send it as a private message to me. To do that, click on my E circle and select message and send it that way. I will put it into my editor and see what is going on. But, remember, I will not be able to see the missing files… Of course!

Well… no as there is no “HTML” folder in the older Xampp, Xampp/php, Xampp/php/pear. So the files have never been there. While the older “Table.php” is there, and it does refer to those files, I never “had” that problem in the past. So it is getting even more confusing. I renamed the older version of Xampp to Xamppold so I could install the newer version into Xampp, thus keeping the older versions intact… I just installed the latest version (hoping that it may “fix” the problem but nup same errors basically…

The new error still points to the line 68 in the Table.php file but there is a little more “information” in the error:

Warning : require_once(HTML/Common.php): Failed to open stream: No such file or directory in C:\xampp\php\pear\Table.php on line 68

Fatal error : Uncaught Error: Failed opening required ‘HTML/Common.php’ (include_path=‘C:\xampp\php\PEAR’) in C:\xampp\php\pear\Table.php:68 Stack trace: #0 C:\xampp\htdocs\ComputerSuperStore\tablelogincheck.php(10): require() #1 C:\xampp\htdocs\ComputerSuperStore\index.php(31): require(‘C:\xampp\htdocs…’) #2 {main} thrown in C:\xampp\php\pear\Table.php on line 68

Ok that information has given me a bit of an idea.
I looked at tablelogincheck.php (which hasn’t been referred to in the past) and it points to a file called table.php (which is in my folder) so I am wondering if I have to give it the full address, to point it to the one in my folder and not to the one in the php/pear folder. although why it would go there is beyond me. My table.php file only has 15 lines compared with the other one which has over a thousand lines.

That said the table.php is in the same directory / folder as the tablelogincheck.php, so one would think it should look at that first…
Rather than add a new post I figured I’d edit this one.

I simply changed the name of my table.php to tableo.php and changed the require function to the same file and it has fixed that problem… marvelous what a “seat in the Throne-room” can do lol…

The products are now displaying…

New Edit
Checked the sign in Function, and it failed, did a bit of checking and there were some components missing from the "Customer part of the Database, found them in an older file, deleted to faulty DB and Imported the complete DB but still getting an error

Fatal error : Uncaught ArgumentCountError: mysqli_real_escape_string() expects exactly 2 arguments, 1 given in C:\xampp\htdocs\ComputerSuperStore\checklogin.php:32 Stack trace: #0 C:\xampp\htdocs\ComputerSuperStore\checklogin.php(32): mysqli_real_escape_string(‘Joe’) #1 {main} thrown in C:\xampp\htdocs\ComputerSuperStore\checklogin.php on line 32

Line 25 to 53:

  1. <?php // Define $myusername and $mypassword
  2.      $myusername=$_POST['UserName'];
    
  3.      $mypassword=$_POST['Password'];
    
  4.      // To protect MySQL injection (more detail about MySQL injection)
    
  5.       $myusername = stripslashes($myusername);
    
  6.       $mypassword = stripslashes($mypassword);
    
  7.       $myusername = mysqli_real_escape_string($myusername);
    
  8.       $mypassword = mysqli_real_escape_string($mypassword);
    
  9.       $sql="SELECT * FROM customer WHERE UserName='$myusername' and Password='$mypassword'";
    
  10.       $result=mysqli_query($sql);
    
  11.         // Mysql_num_row is counting table row
    
  12.         $count=mysqli_num_rows($result);
    
  13.          //If result matched $myusername and $mypassword, table row must be 1 row
    
  14. 	     if($count==1){
    
  15.          // Register $myusername, $mypassword and redirect to file "success.php"
    
  16.          $row = mysqli_fetch_array($result);
    
  17. 		 $_SESSION["UserName"]=$row['UserName'];
    
  18. 		 $_SESSION["CustId"]=$row['CustId'];
    
  19.          //session_register("myusername");
    
  20.          //session_register("mypassword");
    
  21.          echo '<script>window.location.href="success.php"</script>';
    
  22.          }
    
  23. 	     else {
    
  24.          echo "<script> window.alert('Wrong Username and Password!'); </script>";
    
  25.          echo '<script>window.location.href="login.php"</script>';
    
  26.          }
    
  27.       ?>

Nobody really uses this anymore. To protect for MySQL injections, you just filter all of your inputs when the user posts to PHP code. To do this, it is super easy. You change the lines that get the data from the posted form, like, $myusername=$_POST['UserName"]; and change to something like this:
$myusername=filter_input(INPUT_POST, “UserName”);
This newer function takes the input from the POST command, filters out programming codes and invalid data so that is it cleaned. Next, you do not directly use that data inside the query. You need to learn about PREPARE commands. You “prepare” a query and use “?” where the data goes and then you execute the command. It is not hard to understand. But, what this does it bypass any possible attack from a hacker. They can NOT get to the data that is inserted or used in queries. So, in you example where you select data based on inputs, only the server ever has access to it.

Therefore, your next step is to alter all of your code in the entire project where they get data from the $_POST array into a variable to use the newer filter_input function. You can read up on it at php.net or w3schools.com or just Google it. Or, ask question on it here. Also, remove all the stripslashes and real escape string functions as you no longer need them. And, lastly change the queries to use prepared statements. There are many tutorials on this conversion. Here is one that explains the reasons why and how SQL Injection works. I think it will help! MySQLi Prepares

One other comment… Normally when you test a site, you place ALL sub-files and libraries under the main folder. You never keep files outside of that folder. The reason is when moving to a live server, you need to have the entire site in one folder. So, you should never use files in other folders like php/pear or others. Make sense?

Good luck! Sounds like you are making headway !

Thanks again for your assistance and advice. Unfortunately, that was the coding we were taught to use back in the day. So yes it is very outdated. As for the storage, yes all of my files for this site are in the one folder/ directory, except of course the Database files, they have to go into the sql folder/ directory. Luckily I had a copy of the site and database stored away in an old TAFE Folder. Not having touched very much on server side scripting since I left TAFE, I think I did myself an injustice not trying to follow up to keep up. I have tried to find resources to get updated scripts/ code but very difficult to find code that actually works.

As for the file outside of my folder, well I don’t know why but it automatically went to that file (Table.php) which was in the pear folder, as it should have went to the table.php in “My” folder/ directory, as it did in the past. That’s why I changed my file to tableo.php and altered the code to point it to that file. All of my php files are in the Main Directory for the site, things like images, CSS files, JavaScript Files are in their own Sub Folders/directories as we do with non server-side standard HTML Sites Thanks again, for all the help.

Sponsor our Newsletter | Privacy Policy | Terms of Service