Discuss Does anyone know where is the error? in the PHP Development forum on Dev Shed. Does anyone know where is the error? PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Posts: 163
Time spent in forums: 1 Day 13 h 18 m 54 sec
Reputation Power: 17
Well ive been getting bashed for using these old mysql extensions as well. However your $test is not the email address. From other users statements it is advised to switch to either MySQLI or PDO rather than the old MySql Extension. However to correct your code from its current state without changing to the newer methods you should first make sure that $user is set before it is used. then you will need to fetch an array from the result of your query.
BUT apparently these are old methods and the people who posted before me know much more than i do so i would listen to them and switch to a newer method of querying your database from php.
Quote:
Originally Posted by requinix
$test is not the email. It is a resource which you use to get the data from the results of the query.
If you change your code to use PDO instead you'll fix the problem along the way.
Posts: 1,871
Time spent in forums: 1 Month 2 Weeks 2 Days 52 m 40 sec
Reputation Power: 813
Quote:
Originally Posted by requinix
some members have made it their goal in life to yell at code involving mysql. don't mind them
requinix, you've been here for many years, so you should really know better. Making fun of people who try to help others on writing modern and secure PHP is pretty lame, and I find it surprising to hear that from a moderator of a PHP forum.
There's a reason why some of us "made it their goal in life" to recommend modern database extensions as opposed to the "good old" mysql_ functions:
The old MySQL extension makes it hard to write secure code, and the people/tutorials still using it almost never get it right -- when you see mysql_query() being used, you're likely to see it in the context of
mysql_query("SELECT * FROM users WHERE id = $_GET[id]") or die(mysql_error());
Prepared statements are by far the safest and most foolproof way to pass values to queries -- but the old extension doesn't have this feature. All it has to offer is mysql_real_escape_string() to escape every value by hand.
Being deprecated, the old MySQL extension will be removed sooner or later. So starting a new project with it might not be the best idea.
The old extension has no support whatsoever for advanced techniques (stored procedures, transactions)
You may laugh about that, but some of us actually care about good code. If you don't, I wonder why you're here.
Posts: 163
Time spent in forums: 1 Day 13 h 18 m 54 sec
Reputation Power: 17
Jacques,
I definately appreciate that you pushed me in the right direction as far as pointing out that it will soon be discontinued; however, we also have to understand that most websites out their, most colleges, still teach mysql_query. While it is advisable to push them in the right direction to plan for the future so that like me where i have 20,000+ line php systems running old mysql extension, i am sure one day i will run an update on my PHP and find that my application is broken. Also we must look at the fact that most open source or commercial systems are written with these old queries.
I do not mind the criticism but also keep in mind mysql_query is being phased out not dead yet.
Quote:
Originally Posted by Jacques1
requinix, you've been here for many years, so you should really know better. Making fun of people who try to help others on writing modern and secure PHP is pretty lame, and I find it surprising to hear that from a moderator of a PHP forum.
There's a reason why some of us "made it their goal in life" to recommend modern database extensions as opposed to the "good old" mysql_ functions:
The old MySQL extension makes it hard to write secure code, and the people/tutorials still using it almost never get it right -- when you see mysql_query() being used, you're likely to see it in the context of
mysql_query("SELECT * FROM users WHERE id = $_GET[id]") or die(mysql_error());
Prepared statements are by far the safest and most foolproof way to pass values to queries -- but the old extension doesn't have this feature. All it has to offer is mysql_real_escape_string() to escape every value by hand.
Being deprecated, the old MySQL extension will be removed sooner or later. So starting a new project with it might not be the best idea.
The old extension has no support whatsoever for advanced techniques (stored procedures, transactions)
You may laugh about that, but some of us actually care about good code. If you don't, I wonder why you're here.
Posts: 1,871
Time spent in forums: 1 Month 2 Weeks 2 Days 52 m 40 sec
Reputation Power: 813
I'm aware that many books/tutorials still teach the old mysql_ functions and that there are many legacy applications around which cannot simply be rewritten. That's a fact we cannot change.
But what we can change is when people have just started with PHP and only use the mysql_ functions because they've read a bad "tutorial" and don't know better. In this case I think we should definitely tell them to stay away from the old extension and use the modern ones right from the beginning.
Sometimes this might come off as pretty rude, but that's because you see the same bad code from the same bad "tutorials" in almost every reply. It's like the same dog sh*tting in your front yard every day, and all you can do is clean it up.
Posts: 163
Time spent in forums: 1 Day 13 h 18 m 54 sec
Reputation Power: 17
It's alright. I personally enjoy being attacked. just take it as a learning experience. It was a bit of a shock to me mostly because are company is still pushing the old extension in are procedures which i now plan on addressing when i return to work. Is their any news of when this extension will be officially no longer supported by PHP?
Quote:
Originally Posted by Jacques1
I'm aware that many books/tutorials still teach the old mysql_ functions and that there are many legacy applications around which cannot simply be rewritten. That's a fact we cannot change.
But what we can change is when people have just started with PHP and only use the mysql_ functions because they've read a bad "tutorial" and don't know better. In this case I think we should definitely tell them to stay away from the old extension and use the modern ones right from the beginning.
Sometimes this might come off as pretty rude, but that's because you see the same bad code from the same bad "tutorials" in almost every reply. It's like the same dog sh*tting in your front yard every day, and all you can do is clean it up.
Actually, our company also has a lot of legacy code with the old functions, but I'm not aware of any plans to change this. No customer would be willing to pay for a major rewrite without any visible outcome.
So it's like with any other legacy code: It works as long as it has to work. For new projects, however, I'd definitely address this issue.
Actually, our company also has a lot of legacy code with the old functions, but I'm not aware of any plans to change this. No customer would be willing to pay for a major rewrite without any visible outcome.
So it's like with any other legacy code: It works as long as it has to work. For new projects, however, I'd definitely address this issue.
Posts: 1,871
Time spent in forums: 1 Month 2 Weeks 2 Days 52 m 40 sec
Reputation Power: 813
Quote:
Originally Posted by mohnish
in this query 'usuarios' might be the error.....usuarios used as column name and table name...might be name conflict...check once
Apart from the fact that this thread is two weeks old: Have you read anything of what people said in this thread? There is no naming conflict, because the table is called "usuarios" with an "s" at the end, while the column is called "usuario" without an "s". I'm also pretty sure that you can give both a table and a column the same name.
In fact, there isn't even a query error, because in #3 the OP said he is getting a MySQL resource. So he just didn't know that he had to actually fetch the value/row he wants (as stated in #4).