First of all, if you are just starting out you need to stop right now.
I need to first point out you are using an extension that does not exist in PHP anymore. mysql is long gone, you have to use mysqli or PDO to communicate with your database.
If you have been using mysql functions, that means you were also using an obsolete and unsupported verion of PHP because it simply won’t work in current versions.
There is no point starting out learning obsolete code.
You need to use a current PHP version and that will mean using mysqli of PDO too.
I am using PHP 5.4 i think. Well i understand but i got this work and i am not able to do a lot of changes!
I want just to start modifying this and achieve something!
Can you please help me out with this problem ?
Well I’m not exactly clear what you are trying to do, the query does not make sense with the question.
You are asking about counting, but using a query limited to one result.
As you can see in the photo!
I want to count how much are with PLR_ID = $userid and ITEM_ID = 2
Example in the photoo
PLR_ID = 2 and ITEM_ID = 13
I want to show that are 10 that have PLR_ID = 2 and ITEM_ID =13
I hope i explained good! I hope
Set your values instead of :item_id and :user_id. They both are placeholders by PDO preparing and actually PDO with preparing strongly recommended for work with relational databases.
Ok. This is the first step you should actually get working first. I highly highly highly suggest you not try to code in PHP first of all since the main problem is not being able to get the SQL started. What I strongly suggest is that you either use MySQL Workbench or some alternative. Try getting the SQL to actually work properly before you start implementing it into a PHP code. This is the most effective route because you will know 100% that your SQL statement actually works properly.
The next thing after that is to properly write PHP code. The mysql_* extensions have long since been dead and there is no legitimate reason to be using these. No matter what version of PHP you are using, there is no legitimate reason to be using them anymore. It’s not some kind of “scare tactic” to make you switch. There really is no reason to be using mysql_*. You should be using mysqli_* or PDO as both @SamA74 and @igor_g has been alluding to the whole time. Don’t use regular queries (->query or _query), use prepared statements (->prepare) because you are dealing with user input.
The second error is a direct result of the first error. Because your query did not execute, when you try to use the results of that query, you won’t be able to because the results do not exist. Hence the variable is undefined.
Step 1: run your query from phpmyadmin or whatever you used to create the database and put that information into it. Once you have a working query, then you can look at how to run the query from PHP and use the results.
There is a reluctance on here to help anyone learn how to use an outdated set of functions. The mysql_ library was removed from the language for PHP 7. I understand you just want to get something working so you can build on it, but it’s really not the correct way to go. You can use PDO (which would be my choice over PDO) without having the complexity of prepared statements, and then learn about those later on once you’ve seen something working. But it really is a bit of a waste of your time to learn how the old functions work, unless you’re planning to spend your time converting outdated systems to use the new versions.
You don’t need to change PHP version to use PDO, as it was included from PHP version 5.1. It would be better to be on a newer version, but not mandatory.
If it isn’t prepared statements but the OOP syntax that’s holding you back you should try mysqli (mysql improved) that can be written with both OOP and procedural syntax. It doesn’t have my preferred named placeholders but does have prepared statements.
In any case, mysql (the extension, not MySQL the database) is now obsolete and any version of PHP that supported it - this is important - has reached End Of Life and no longer gets any fixes at all including security fixes.