Jump to content

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();

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.