Jump to content

Archived

This topic is now archived and is closed to further replies.

anticore

bad syntax? help

Recommended Posts

do i have a syntax error around here ? it just outputs a blank page..
[code]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');
}
[/code]

Share this post


Link to post
Share on other sites
Let's go through first, my basic thoughts on how to troubleshoot this issue.

Here's the updated code:
[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'];
    }
?>[/code]

First I added the [b]$debug = true[/b] 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!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.