SQL: Query Not Working


For whatever reason, I cannot get this query to work:
	$sql = "SELECT * FROM states ORDER BY state ASC";
	$result = mysql_query($db_connect, $sql);
	if (mysql_num_rows($result) > 0) {
	while($row = mysql_fetch_assoc($result)){
	<option value="<?php echo  $row["state"]; ?>" ><?php echo $row["state"]; ?></option>

Open in new window

Any ideas as to why?
Joseph LongoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mukesh YadavFull Stack DeveloperCommented:
Are you getting any error?
HuaMin ChenProblem resolverCommented:
Does the table exist? Is the connection working fine? Please remove ASC in your query.
Ray PaseurCommented:
Please refer to this article for two important points.

First, it will show you how to visualize error information.  When database extensions fail, they fail silently, and you must use PHP to tell them to give you the error information.  This should become part of your standard coding practice.  Look through the article code samples for the exact phrase, "LOG AND SHOW THE ERROR" to see how to test for failure and get the error messages.

Second, it will show you how to get off of the MySQL extension and make the required move to MySQLi or PDO.  There is no current support for MySQL in PHP -- it has been removed.  You must upgrade  your script in order to keep it running!

You might want to add error_reporting(E_ALL) to the top of your PHP scripts, too.  This will help you catch situations that rely on undefined variables.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Joseph LongoAuthor Commented:
Apparently, for whatever reason the query doesn't work on my computer at home. I have an old MacBook Pro ---like 11 years old, which is running an older version of PHP. However, once I upload my scripts from my older machine to a newer machine and use mysqli, the script works as is. So, no worries. Thanks everyone for their assistance.
Ray PaseurCommented:
I would love to have an old MacBook Pro!

Glad things are looking up.   Best of luck with your project, ~Ray
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.