Jump to content

bad syntax? help


anticore

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]
Link to comment
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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.