Lambneck Posted July 14, 2009 Share Posted July 14, 2009 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 More sharing options...
BoarderLine Posted July 14, 2009 Share Posted July 14, 2009 In your SQL Query $sql = "SELECT * FROM $table WHERE topic=$id"; what is $table? you need to enter your database table name here. Also you should wrap the $id in '#id' Link to comment https://forums.phpfreaks.com/topic/165892-solved-trouble-with-_get/#findComment-875018 Share on other sites More sharing options...
Lambneck Posted July 14, 2009 Author Share Posted July 14, 2009 $table is a predefined variable; and even with the quotes i get the same unfortunate result. this is the first time ive used urlencode so i thought it may have something to do with that. but its right as far as i can tell. ??? Link to comment https://forums.phpfreaks.com/topic/165892-solved-trouble-with-_get/#findComment-875025 Share on other sites More sharing options...
exhaler Posted July 14, 2009 Share Posted July 14, 2009 did u try it without the urldecode/urlencode? Link to comment https://forums.phpfreaks.com/topic/165892-solved-trouble-with-_get/#findComment-875046 Share on other sites More sharing options...
kenrbnsn Posted July 14, 2009 Share Posted July 14, 2009 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 Link to comment https://forums.phpfreaks.com/topic/165892-solved-trouble-with-_get/#findComment-875060 Share on other sites More sharing options...
Lambneck Posted July 14, 2009 Author Share Posted July 14, 2009 “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!'; } ?> Link to comment https://forums.phpfreaks.com/topic/165892-solved-trouble-with-_get/#findComment-875119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.