Solved

SQL question....

Posted on 2002-05-06
5
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
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…

734 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