Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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