Solved

SQL question....

Posted on 2002-05-06
5
268 Views
Last Modified: 2006-11-17
Hi,

Why does this sample of code just produce a blank page?

<?php

$cat=test;

$conn=mysql_connect("host","user","pass");
if(!$conn){
       echo"cant connect";
       die;
}

mysql_select_db("testdb");

$qid=mysql_query("SELECT * FROM testtable WHERE cat=$cat");

while($row=mysql_fetch_array($qid)){
?>
<table>
<tr><td><?=$row[heading]?></td></tr>
<tr><td><?=$row[message]?></td></tr>
<tr><td><a href="/folder/subfolder/script.php?id=<?=$row[id]?>">LINK</a></td></tr>
</table>

<br><br>
<?}?>

I am a SQL newbie, and I think there's something wrong with the "SELECT * FROM testtable WHERE cat=$cat" part, but have been unable to fiqure it out.

Thanks,
Nick!
0
Comment
Question by:Nick50000
  • 2
  • 2
5 Comments
 
LVL 32

Accepted Solution

by:
Batalf earned 95 total points
ID: 6991722
Something you could test:

1) Change $cat=test;

to $cat="test";

2) $qid=mysql_query("SELECT * FROM testtable WHERE cat=$cat");

I't always a good thing to put $cat into single-quotes, like this:

$qid=mysql_query("SELECT * FROM testtable WHERE cat='$cat'");

Batalf
0
 
LVL 4

Expert Comment

by:lokeshv
ID: 6991734
put $cat in '',

then echo ur query and check...is that alrite ?

is till doesnt work ...


put this few lines after

$qid=....

if(!$qid){

echo 'Error :'.mysql_error();
}

and check the error...


Hope this helps..

LK

0
 

Author Comment

by:Nick50000
ID: 6991760
O.K thanks, i'm trying that now.
0
 

Author Comment

by:Nick50000
ID: 6991815
Great, your advice worked first time....

Problem solved!

Thanks,
Nick!!!
0
 
LVL 32

Expert Comment

by:Batalf
ID: 6991822
Glad I could help.

Batalf
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Whether to use true/false, yes/no or 0/1 11 51
myqsl update statement on phpMyAdmin 8 22
Intermittent Error on Page Loading 4 20
php construct 5 13
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now