Jump to content

Struggling With Get on Receiving Page


justlukeyou

Recommended Posts

It still doesn't make too much sense. What do you want to accomplish with $ID. Your best bet would be to grab a SQL book and learn basic SQL statements. There is a MySQL Help forum.

 

My guess: $sql = sprintf('SELECT * FROM `articles` WHERE `col_id_field` = %d;', mysql_real_escape_string($ID));

no need to sort by ID since this is the page that will retrieve the id from your previous list. You would sort that list by ID.

<?php
$ID = mysql_real_escape_string($_GET['ID']);
$sql = "SELECT * FROM articles WHERE ID = '$ID';
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res); // no need to loop since you are retrieving only one row
$num_rows = mysql_num_rows($res); // check to see if any results were found, just in case someone puts an ID in the url without clicking on your link
if($num_rows > 0)
{
echo $row['ID'].' '.$row['title'].' '.$row['intro'];
} else {
echo "No results found";
}

?>

 

Try it out

 

Ray

Brilliant, thanks ever so much for this.

 

It did create one error so I took out the query and put it in a string and did echo the results which is just test material so its definately getting there.

 

SELECT * FROM articles WHERE ID = ''2 Cats Are Best You will find Cats are the best

 

$query_string= "SELECT * FROM articles WHERE ID = '$ID'";
echo $query_string;

$query = mysql_query($query_string);

 

 

This the error it created:  syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/ukhomefu/public_html/articles/article.php on line 137

 

Which refers to this line:

 

echo $row['ID'].' '.$row['title'].' '.$row['intro'];

 

Does the error above mean anything to anyone?  Should there be brackets somewhere?

 

Could echo this way.

echo "{$row['ID']} {$row['title']} {$row['intro']}";

 

Is no difference.

 

I'm stumped at this line:

 

SELECT * FROM articles WHERE ID = ''2 Cats Are Best You will find Cats are the best

 

What is that and where did it come from?

Hi,

 

This line is what was echoed onto the screen when I put the query into a string.

 

SELECT * FROM articles WHERE ID = ''2 Cats Are Best You will find Cats are the best

 

The ID is 2

Title:    2 Cats Are Best

Intro:  You will find Cats are the best

 

So it does work but only when I put it in a query string which also echoes the query.

 

Does this help at all?

Hi,

 

echo $row['ID'].' '.$row['title'].' '.$row['intro'];

 

It creates this error. Does anyone have any suggestions on what I can do to resolve this.

 

This the error it created:  syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/home/public_html/articles/article.php on line 137

 

Can I add something like this or die(mysql_error()); to get more information?

Please see below all the code I have:

 

<?php
$ID = mysql_real_escape_string($_GET['ID']);
$sql = "SELECT * FROM articles WHERE ID = '$ID';
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res); // no need to loop since you are retrieving only one row
$num_rows = mysql_num_rows($res); // check to see if any results were found, just in case someone puts an ID in the url without clicking on your link
if($num_rows > 0)
{
echo $row['ID'].' '.$row['title'].' '.$row['intro'];
} else {
echo "No results found";
}
?>

You probably should make sure GET isset before running query.

<?php
if (isset($_GET['ID'])){
$ID = mysql_real_escape_string($_GET['ID']);
$sql = "SELECT * FROM articles WHERE ID = '$ID';
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res); // no need to loop since you are retrieving only one row
$num_rows = mysql_num_rows($res); // check to see if any results were found, just in case someone puts an ID in the url without clicking on your link
if($num_rows > 0)
{
echo $row['ID'].' '.$row['title'].' '.$row['intro'];
} else {
echo "No results found";
}
}
?>

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.