Older PHP & MySQL no longer working in Later Versions

Ok I’ll try to explain as best I can the “Why’s”
Firstly, this is a fictitious web site - it doesn’t actually exist in the real world - That said I am hoping to create a web site for my DJ Karaoke Business where Punters can search for a specific song, or an Artist etc.

Now the site where the errors are is a Fictitious Computer Store. Customers can create an account, Look for Products, to buy a product they must be logged in.

Now, In the Search area it is just a text box and a button. And when they search, I want to display all details about the product, as well as an image (or images for multiple Products) so Select * From Product (table) is necessary in this case - now the search option is available for all users whether they are logged in or not. So we need to have the Brand, the Size, The Image, The Price, ant The Details displayed on the screen once the search is completed. Hence why there is only one “Parameter” Let’s say thew search is for Monitors. You Type in Monitors in the Text Field, hit Search, then all Monitors should be displayed in the result screen (Not just Text Listing) but all the details of each product/ Monitor Will be displayed. Now all of this worked fine without any errors at all when I first built the site in 2012 when I did the course, BUT 2.5 years later, Nothing worked after I installed the Later Version Of PHP & MySQL. So I have been trying to solve these issues since about Mid 2015, some of the problems I was able to fix. The first one was connecting to the Database. Now that is done in a file of its own (in this case header2.php) Now each page has at the very top

$PageTitle= "Page Name"; // (what ever the page is)
require ("header2.php");

Then there is all the HTML code for the page
Now From memory we used get ('header2.php");
But that was the very first error the new version did not recognise “get” when it come to adding pages using php, so I found the new term was “require” - that was fixed
Now the first lines of header2.php has:


Then the HTML
Originally the php further down read

  $con = mysqli_connect("localhost", "root", "");		//create connection to the database""
    die('Sorry databse is unavailable: ' . mysql_error());
   mysqli_select_db($con, "computersuperstore");
   require ('topbar.php');

But someone told me to use


Before the $con term/ script… whatever.
I did but it has made no difference
That being said It does connect to the database - if not - the page would stop loading

Let’s say there is a hell of a lot of Code even in just the Header.
Way too much to put here.
All that said, my point is, is that EVERYTHING worked before I Updated PHP and MySQL
I’m a bit old school - If it ain’t broke, don’t fix it - I have no Idea why after updating, nothing works properly. The Home Page works fine - No Errors - but Sign in, Add Account, and Search is not working.
So, I can’t even tell if selecting an item and putting into the cart will work (After Sign In Gets Fixed)
I am stressing as to just how much “wont” work anymore.

As for why we used all the coding we did - well that was as per instruction - so there was not much choice as “I” was learning from scratch - I had front end coding pretty much set, but the backend coding was all new to me, so I could only be guided by what the instructor told me. Perhaps, back then (In 2012) it was ok to use the coding practices we used… I was an inexperienced student when it came to Backend coding… I do get times change, but maybe some things should be backward compatible…
I am not sure how to get the coding to you but like I said there is heaps of it
header2.php has 64 Lines php and html
search.php has 64 lines php and html
index.php has 44
And so On
So tell me what you need from me to make sure earlier code wont clash with what you are giving me
There are 75 Separate php item that the site uses (not all at the same time) but if and when they are required, there is an include parameter.
As I said earlier I have spent years trying to work out the problems, I get told to do “this” but later I get told that that was wrong… hence my outburst I Quit…

Anyway I await your reply…

With regard to the error messages in your first post, have you been able to take the information provided by various posters here and at least get past those errors?

I’m not surprised that you were instructed to do things the way you were at that point in time, but as you’ve since upgraded the PHP version, it’s only to be expected that things might change.

Well, kind of, and I fully agree with that sentiment. But you also upgraded the PHP version, so if that wasn’t broke, why would you do that? Obviously without knowing what the previous version was, and what you upgraded to, it’s difficult to comment further, but when upgrading PHP versions it might be a good thing to check release notes to see what might break.

Well, the way to do this is pick things off one at a time and fix them. If you’ve got lots of query lines where you haven’t included the connection parameter, you now know what’s wrong and you can go through and fix all of them, and that might be a good step along the way to fixing things. At the moment, using the query syntax you provided in your first post in this thread, none of your queries will work. To be explicit, this line:


needs to be changed to read:

$numresults=mysqli_query($conn, $query);

where $conn is the variable you used when you connected to the database, which you’ve said is working correctly. Once you’ve done that line and seen that the error message goes away, you can fix the same fault on line 51 in your post, and then all of the rest of them.

As for the other errors and “won’t work” bits, all you can do is go through them step by step until they work for you, and come back for specific advice if you need it.

Once you have it working, you can look at changing your queries to use parameters instead of the way you’re doing it now. Everything that posters above have said is absolutely correct, but I just wonder if they present too many changes that make the job look more daunting than it needs to be, when all you want to do is make the site work again.

1 Like

Maybe one more word…

Fixing this takes time. Much time. You need to spend hours over hours. But, no one else could do it faster for you. We would need hours too. That’s the disadvantage when you never maintain a code for years. Then you will get at a point where you need to invest all the time you did not in smaller parts all the years before….

1 Like

This is where code maintainablitiy comes in. It was mentioned earlier, it’s best to separate different parts of code that deal with different things, such as keeping your database intaraction separate from your HTML output.
When things are organised better, updating, correcting and tweaking becomes much simpler.
As an example from code you have posted:-

You are only really going to need to write your database connection once ever in a site/application,except when using different users/permissions, but for a read only connection, have this connection written once only in its own PHP file, then require_once in any place where you need the connection.
Why? You probably have this connection code duplicated in several scripts all over the application. When the time comes you need to edit that connection code (like now), you need to hunt down and edit several times in several files. Or you could just do it once, in one file, and every other script that requires that file will be up to date just like that. This principle of coding is known as DRY (Don’t Repeat Yourself).
That is just one example of how life can be much simpler with better organised code, which makes doing updates like this a whole lot less daunting.
Unfortunately because it wasn’t done this way in the start, there is no such short cut to modernising your code. The question now is: do you take a short cut now, which will lead to a long road maintaining in the future, or do you take the long road now, which will lead to easy short cuts in future?

1 Like

Ok, the version of PHP - MySQL we used back then was what ever the current version was in 2012.
To the second part of your question… Ok I built a website for my DJ and Karaoke “Businesses” and use a hosting service to run the site (as one does) That was mid 2015… I decided to have my “Home Page” which outlined what I do. Then I loaded more detailed pages as a Subsite. so back then my site was called kcs_services.com.
The Sub Sites were karaoke, dj and whatever else. as a subsite they are written as karaoke.kcs_services.com. The appearance of the page is fundamentally the same, there are noticeable differences between the home page and the karaoke page. Once I set up my other business pages as subsites, I decided to (as a test) load my fictitious site up there including the database and other associated files. so now the fictitious site was computersuperstore.kcs_services.com. Now, when I loaded everything up to where they had to be loaded, My subsite did not work, it would not even connect to the database. So, I contacted the host of my site, explained what happened, and they looked into it. They confirmed that I had loaded all Files and items to the correct places - eliminating location of files as a cause. After a few days, they contacted me and asked me what version of PHP MySQL I had installed on my Computer. From Memory PHP 5.4 and MySQL 5.5 (I think) it was 12 years ago so I can’t be 100% Certain. But, in order for me to “Fix the Errors” I had to Update My software. Simple. No Point in using the older version, as the hosts use later versions, So, in order to make my site compliant, I HAD to have the later versions… I hope that answers your question.

In your comment, you say spend some time… Ok I first created the site in 2012. On my computer using XAMPP which had the current versions of PHP and MySQL it all worked, However when I decided to Experiment, I uploaded my fictitious site up to my "real site and created a subsite. But It didn’t work That was mid 2015, so between November 2012 and May-June 2015 PHP and MySQL changed significantly. Now while I have not spent:
Every Second of Every Minute,
Every Minute of Every Hour,
Every Hour Of Every Day… And so On, I have spent the last 9 years “trying” to fix these errors. So, yeah, I “HAVE” spent a hell of a lot of time trying to sort it out, so in reply to that part of your comment, I HAVE done as you suggested.

In 2012 I think the current PHP version would be 5.something, I don’t know exactly what you used.
That would likely support mysql.
In PHP 5.5 (released 2013, one year after 2012) mysql was deprecated, that meant that it still would work, but it gave a warning to let you know that it was obselete and to be removed in future versions of PHP. The purpose of the message, that you need to update this to something current because it won’t continue to work. A fair warning in good time.
Mysql remained deprecated for the rest of PHP version 5 and was finally removed in PHP 7 released in 2015.
Though PHP 5.6, the final version where mysql would still work was kept in support until 2018. Ordinarily it would have been “End of life” much sooner, but they kept it going longer because there were a million (more really) Wordpress and other PHP stites still out there who had not yet acted on the warning and updated their code. So they kept PHP 5.6 alive a bit longer just to allow all the stragglers to catch up before fully pulling the plug on mysql.

So if you haven’t yet realised from this topic, the message we are giving is, your site was built using mysql to connect with the database. That would work in PHP 5. But PHP 5 was end of life 5 years ago.
Therefore your database connection won’t work on current version 8. This is nothing new, in fact it’s an old problem whereby I don’t recall the last time it came up in the forums, and it has been warned about more than 10 years ago.

The remedy is to update all database code to use a currently supported database connection, those being mysql or PDO.
Mysqli has been around since PHP 5 in 2004, that’s 20 years ago.
PDO was added in PHP 5.1 in 2005, almost as long.
Really a course in 2012 should not have been teaching the use of mysql shortly before its demise when better more future proof options exited.
Now when it cones to migrating from mysql, you make the choice between mysqli and PDO. People naturally gravites to mysqli, because it seems more similar and familiar and doesn;t have the “scary” OOP implications. And it probably is more similar, but that’s why it’s a bad choice IMO.
My personal recommendatin is go for PDO, I just think it’s better in every way. I think anyone who has used all three would agree, though if anyone begs to differ, then do.
OOP may seem intimidating, but it’s enlighening once you get your head around it, and in honesty you don’t need to do that just to use PDO and its methods for basic database interactions.
The syntax for prepared statements is much simpler and less verbose than mysqli, plus it has some really useful fetch modes that I like a lot.
The other point toward your concerns, the knowledge to use it isn’t hidden behind some paywall whereby you will have to pay for a course to learn it. Information is readily available online. Though I add to that the disclaimer, be careful where you learn from online, not everyone shows the right way. I’m sure people here can point you in the right direction. You already have some code samples here.

Hi, I did try your suggestion. at first it didn’t work, I got an error $conn not recognised, however I decided I would experiment and used $con. This worked. Yes there were more errors further down the page(s) but one by one I was able to fix them. So now, as a visitor I can search, and I get results without any errors. I can now log in, and the “logged in” page loads - where there are buttons to add items to our cart.
I can create an account without errors. I can log in with that new account. At this stage, adding to the cart - or rather “viewing” the cart is a mystery - I can view the cart, BUT, nothing is added, I there are no error messages. Again back in 2012, I could add items to the cart, see them in the cart, then go to the checkout. Now This was all covered in the Diploma Of Web Development ICA50611 in 2012. We did not get to the point of actually making a purchase with PayPal or Credit Card, that was covered in the “Advanced Diploma” in Web Dev, and that was only available at University (Here in Australia) I mentioned “TAFE” a few times, that is the acronym for Technical And Further Education (for those of you not in Australia, and who may not be aware of our education System.) But in short, TAFE is a College system that runs many Courses, that are written using an international Standard, and at the time it was all up to date. Now I saw some comments about my Coding Method, One felt like a bit of ridicule. Well In 2012, that was the way things were done. Including mixing php AND HTML in the same page. For that matter, we used a book “Build Your Own Database Driven Website Using PHP & MySQL”, by Kevin Yank. Oh it was produced by none other than SitePoint. So before you completely dismiss my coding methods for back then, consider it was the way we were taught. And if we did not use the methods (even if the alternative we used was “correct”) we lost marks, for not following the instructions we were given. As for the Cart problem, with no Error message I am seriously at a loss.

So Thank-you droopsnoot for the advice you gave it has cleared up a lot of problems. Oh and thankyou to all others who took the time to make constructive comments and accept the why’s of what we did.

Where do I go to Learn PDO?

This is probably the best place to learn it.

There was no real need to experiment, I did imply that you needed to replace $conn with whatever variable name you had used for your database connection. However, I am glad things are now working better for you.

As for your trouble adding things to the shopping cart, no-one can give any advice without seeing the relevant sections of the code. You can debug it fairly easily using var_dump() and echo to trace the operation of your code, and to see what variables are being created or updated.

The thing with courses is that, as the student, you have no way to know whether the techniques being taught are up to date, or useful for the real world - if you knew, you wouldn’t need the course. Others here know more about the timelines than I do, but I also know from my own brief experience with education that course curricula tend to stick around longer than they perhaps should do. When I was in college (aged 17-18) in the early eighties, the A-level course still talked about punched cards and paper tape as storage media. I also recall a similar situation to yours - we were taught machine language using a fictitious language for a fictitious processor, a mate of mine provided answers written in Z80 code, and while they were correct, they weren’t the answers they were looking for. Sometimes the assessment is on whether you can learn what they’re teaching, regardless of what it is.

As for feeling that someone might have been ridiculing you, don’t forget that people on here are from many countries, some are not writing in their first language, and some are more “forthright” in their comments than others. So it probably wasn’t really ridicule.