Jump to content


Photo

bad syntax? help


  • Please log in to reply
2 replies to this topic

#1 anticore

anticore
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 15 March 2006 - 11:10 PM

do i have a syntax error around here ? it just outputs a blank page..
mysql_connect($host,$user,$pass) or die("COULD NOT CONNECT TO DB");
mysql_select_db($db) or die("COULD NOT SELECT DB");
//echo " connected ...";
//run query
$query = "SELECT * FROM user_rides WHERE yearcat=".$_REQUEST['yearcat'];

if ($r = mysql_query($query) or die(mysql_error())
{
//print

while ($row = mysql_fetch_array ($r))
{
    print "{$row['name']}";
    
}
else {die('error');
}


#2 Balmung-San

Balmung-San
  • Members
  • PipPipPip
  • Advanced Member
  • 327 posts

Posted 16 March 2006 - 01:02 AM

turn the print "{$row['name']}"; into print "{".$row['name']."}";

"Paranoia is very useful in this work. ...If your cryptographic system can survive the paranoia model, it has at least a fighting chance of surviving in the real world." - Niels Ferguson & Bruce Schneier

They say there's more then one way to skin a cat.
In programming, there's no wrong way to skin a cat, just more efficent ways of doing so.

#3 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 16 March 2006 - 01:08 AM

Let's go through first, my basic thoughts on how to troubleshoot this issue.

Here's the updated code:
<?php
 $debug = true;
 $connection = mysql_connect($host,$user,$pass) or die("COULD NOT CONNECT TO DB");
 mysql_select_db($db) or die("COULD NOT SELECT DB");
 $query = "SELECT * FROM user_rides WHERE yearcat=$_REQUEST['yearcat']";
 $result = mysql_query($query, $connection) or die ("error in your query");
 if ($debug) print $query;
 if ( mysql_num_rows($result) == 0 ) die ("no results were returned..");
    while ($row = mysql_fetch_array ($result)){
        if ($debug) { print "<pre>"; print_r($row); print "</pre>"; }
        print $row['name'];
    }
?>

First I added the $debug = true I created this for the simple fact that sometimes you need to print out the Query statements if shit goes wrong, and this was just a simple way for me to impliment that for current and future troubleshooting.. I pretty much do this for all queries or strings, on generated forms or data from the DB.. it's a practice that once you impliment correctly, can save you SO much time.

Anyway!

If you have any questions regarding the specifics.. the syntax I used, the indentation (something your code was seriously lacking) please don't hesitate to ask specifics.

Good luck!


Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users