Link to home
Create AccountLog in
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?
Avatar of Mukesh Yadav
Mukesh Yadav
Flag of India image

Are you getting any error?
Hi,
Does the table exist? Is the connection working fine? Please remove ASC in your query.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Joseph Longo
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 would love to have an old MacBook Pro!

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