We help IT Professionals succeed at work.

SQL: Query Not Working

Joseph Longo
Joseph Longo asked
on
133 Views
Last Modified: 2017-04-21
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?
Comment
Watch Question

Mukesh YadavFull Stack Developer
CERTIFIED EXPERT

Commented:
Are you getting any error?
Peter ChanProblem resolver

Commented:
Hi,
Does the table exist? Is the connection working fine? Please remove ASC in your query.
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

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.
Most Valuable Expert 2011
Author of the Year 2014

Commented:
I would love to have an old MacBook Pro!

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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions