Jump to content

[SOLVED] trouble with $_GET


Lambneck

Recommended Posts

I've been messing with this for a while now and cant figure it out. I get the following error when Using the below code:

 

"Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Across China' at line 1 with query SELECT * FROM Post_Information WHERE col_2=Travel Across China"

 

Can anyone see what Im doing wrong?

 

	$subject = $row['topic'];
echo '<a href="discussionboard.php?id='.urlencode($subject).'">'.$row['topic'].'</a>';

 

	$id = urldecode($_GET['id']); 

$sql = "SELECT * FROM $table WHERE topic=$id";
$result = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql);
if(mysql_num_rows($result) == 1){
$row = mysql_fetch_array($result);

  	echo '<div class="posts">';

Link to comment
https://forums.phpfreaks.com/topic/165892-solved-trouble-with-_get/
Share on other sites

The error message you posted and the lines you posted do not match.

 

The error says

"Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Across China' at line 1 with query SELECT * FROM Post_Information WHERE col_2=Travel Across China"

yet the code says

<?php
$sql = "SELECT * FROM $table WHERE topic=$id";
$result = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql);
?>

 

You need to post the query that says something like:

<?php
$sql = "select * from Post_Information where col2=$somthing";
?>

 

My best guess given the information posted is that you didn't surround the value in the "where" clause with single quotes.

 

Ken

“Travel Across China" should be the value taken from the table row 'col_2':

 $row['col_2'] 

 

here is a better look at the code:

$subject = $row['col_2'];
echo '<a href="discussionboard.php?id='.urlencode($subject).'">'.$row['col_2'].'</a>';

<?php

require_once('load_data.php');

$id = urldecode($_GET['id']); 

$sql = "SELECT * FROM $table WHERE col_2='$id'";
$result = mysql_query($sql);
if(mysql_num_rows($result) == 1){
$row = mysql_fetch_array($result);

  	echo '<div class="posts">';
  	echo '<h2>';
  	echo '<a href="discussionboard.php?id='.$row['submission_id'].'">'.stripslashes(htmlspecialchars($row['col_4'])).'</a>';
  	echo '</h2>';
  	echo '--<em>';
  	echo stripslashes(htmlspecialchars($row['col_2']));
        echo '</em>   ';
        echo date("M dS, Y", $row['submission_date']);
        echo '<p>';
        echo stripslashes(substr($row[col_5],0,350)).' <strong><a href="discussionboard.php?id='.$row['submission_id'].'">Read more >></a></strong>';
        echo '</p>';
        echo "</div>";
    
}else{
echo 'That record ID does not exist!';
}
?>

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.