Solved

SQL question....

Posted on 2002-05-06
5
283 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

839 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