Solved

SQL question....

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
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 …

758 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

19 Experts available now in Live!

Get 1:1 Help Now