Jump to content

PHP Code Not Querying


justlukeyou

Recommended Posts

I have put together a query which is designed to display a single question from a database.  However, it currently displays all the questions (and notes and category).  The problem is I cant work out how to get it to display just the qid I am querying.

 

This should display phpquestion.php?qid=2 but it just displays all the question as does phpquestion.php?qid=7 etc

 

ini_set('display_errors', 1);
error_reporting(-1);


$query = "SELECT * FROM questions";

if(isset($_GET['question']))
{
$question = $_GET['question'];
$query .= " WHEN qid is '$qid' LIMIT 0, 1";
}

$result = mysql_query($query);

while($row = mysql_fetch_assoc($result))

{

$question = $row['question'];
$notes = $row['notes'];
$category = $row['category'];
$qid = $row['qid'];

echo "$question |
$notes |
$category </br> ";
} 

if ($_GET['qid'] == $qid ) {
echo 'Sorry, this question is not available.  Please visit our <a href="http://www.ukhomefurniture.co.uk">Homepage</a>.';
}

function sanitizeString($string)
{
return mysql_real_escape_string($string);
}

$question = sanitizeString($_GET['qid']);
$query .= " WHERE question is '%$qid%'";

// close connection 
mysql_close();



?>

Link to comment
https://forums.phpfreaks.com/topic/230749-php-code-not-querying/
Share on other sites

Thanks,

 

I tried that but I got even more confused, should I be listing it in a different order? I cant how I can define qid.

 

$query = "SELECT * FROM questions";

{
$qid = mysql_real_escape_string($_GET['qid']);
}

if(isset($_GET['question']))
{
$question = $_GET['question'];
$query .= " WHEN qid is '$qid' LIMIT 0, 1";
}

$result = mysql_query($query);

while($row = mysql_fetch_assoc($result))

{

$question = $row['question'];
$notes = $row['notes'];
$category = $row['category'];
$qid = $row['qid'];

echo "$question |
$notes |
$category </br> ";
} 

if ($_GET['qid'] == $qid ) {
echo 'Sorry, this question is not available.  Please visit our <a href="http://www.ukhomefurniture.co.uk">Homepage</a>.';
}

function sanitizeString($string)
{
return mysql_real_escape_string($string);
}

$question = sanitizeString($_GET['qid']);
$query .= " WHERE question is '%$qid%'";

// close connection 
mysql_close();

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.