Avatar of Joseph Longo
Joseph Longo
 asked on

SQL: Query Not Working

Hello,

For whatever reason, I cannot get this query to work:
<?php
	$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>
<?php
	}
	}
?>
</select>

Open in new window


Any ideas as to why?
SQLDatabasesPHPMySQL Server

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
Mukesh Yadav

Are you getting any error?
Peter Chan

Hi,
Does the table exist? Is the connection working fine? Please remove ASC in your query.
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Joseph Longo

ASKER
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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Ray Paseur

I would love to have an old MacBook Pro!

Glad things are looking up.   Best of luck with your project, ~Ray