Jump to content

[SOLVED] Query Problem


syclonefx

Recommended Posts

I need help I am getting this error.

 

Unknown column 'popwarner' in 'where clause'

 

Here is my Query:

<?php
$VidCat = ($row_rsCategory['CategoryTitle']);
$query1 = sprintf("SELECT * FROM videos WHERE Active = 1 AND Category = %s",mysql_real_escape_string($VidCat));
$result = mysql_query($query1) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
echo '<span class=""><a href="video_pl.php?video_ID=' . $row['video_ID'] . '" class="" title="' .$row['VideoTitle']. '">' .$row['VideoTitle']. '</a></span><br />';
}
?>

 

If I change my query to this:

<?php
$VidCat = ($row_rsCategory['CategoryTitle']);
$query1 = sprintf("SELECT * FROM videos WHERE Category = 'popwarner'");
$result = mysql_query($query1) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
echo '<span class=""><a href="video_pl.php?video_ID=' . $row['video_ID'] . '" class="" title="' .$row['VideoTitle']. '">' .$row['VideoTitle']. '</a></span><br />';
}
?>

Everything works fine.

Link to comment
https://forums.phpfreaks.com/topic/67498-solved-query-problem/
Share on other sites

It's always best to print out your query as a form of debugging add. 

 

<?php
echo $query1;
?>

 

Before the query is executed and the problem may become obvious to you :).

 

Thanks matthewhaworth I got it..

 

%s should have been '%s'

 

<?php
$VidCat = ($row_rsCategory['CategoryTitle']);
$query1 = sprintf("SELECT * FROM videos WHERE Active = 1 AND Category = '%s'",mysql_real_escape_string($VidCat));
//echo ($query1). '<br>';
$result = mysql_query($query1) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
echo '<span class=""><a href="video_pl.php?video_ID=' . $row['video_ID'] . '" class="" title="' .$row['VideoTitle']. '">' .$row['VideoTitle']. '</a></span><br />';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/67498-solved-query-problem/#findComment-338918
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.