raptor30506090 Posted April 10, 2012 Share Posted April 10, 2012 Hi every one im getting an 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 '' at line 1 SELECT * FROM if(isset($_GET['subid'])){ $id = $_GET['subid']; } $query = mysql_query("SELECT * FROM sub_nav WHERE subNav_ID=" . mysql_real_escape_string((int)$id)); $row = mysql_fetch_assoc($query); $table = strtolower($row['subNavName']); // ******************************* This if statment controls the content ************************ if($row['show_hide'] == 1){ $per_page = 2; $pages_query = mysql_query("SELECT COUNT('id') FROM textiles"); $pages = ceil(mysql_result($pages_query, 0) / $per_page); $page = (isset($_GET['p']) AND (int)$_GET['p'] > 0) ? (int)$_GET['p'] : 1; $start = ($page-1) * $per_page; $query = mysql_query("SELECT imageName FROM textiles LIMIT $start, $per_page"); while ($query_row = mysql_fetch_assoc($query)){ echo '<p>',$query_row['imageName'] , '</p>'; } if ($pages >= 1){ for($x=1; $x<=$pages; $x++){ echo '<a href="?p='.$x.'">'.$x.'</a> '; } } Can any one help please Quote Link to comment Share on other sites More sharing options...
MarPlo Posted April 10, 2012 Share Posted April 10, 2012 Hi I think the error is because the column 'id' is between simple quotes, try this: "SELECT COUNT(id) FROM textiles" Quote Link to comment Share on other sites More sharing options...
raptor30506090 Posted April 10, 2012 Author Share Posted April 10, 2012 sorry tryed that no good it shows 2 items from the database and 2 links as it should you only get the error when i hit the link 1 or 2 Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 10, 2012 Share Posted April 10, 2012 Post the entire error, and you say you get an error when you click on a link, is that a link to this page or a different page? Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 10, 2012 Share Posted April 10, 2012 When running queries - especially dynamic ones (i.e. they have variables) I would highly encourage you to create the queries as string variables first. That way if there is an error you can echo the query out for debugging purposes. Also, there is absolutely no reason to use this: mysql_real_escape_string((int)$id) If you have forced the value to be an integer, then mysql_real_escape_string() is not doing anything of value. using (int) is already making the value safe for a DB query Based upon the partial error you posted the only query which that would come from is this one: $query = mysql_query("SELECT * FROM sub_nav WHERE subNav_ID=" . mysql_real_escape_string((int)$id)); BUt, you don't have any error handling that would have displayed that error! Are you sure that is the correct code that is producing the error? Try changing to the following $id = (int) $id; $sql = "SELECT * FROM sub_nav WHERE subNav_ID = {$id}"; $query = mysql_query($sql); if(!$query) { die("Query: {$sql}<br>Error: " . mysql_error()); } Quote Link to comment Share on other sites More sharing options...
xyph Posted April 10, 2012 Share Posted April 10, 2012 You should echo out this query: "SELECT imageName FROM textiles LIMIT $start, $per_page" And post what it outputs. I'm assuming that's where the error is occurring. All of Psychos advice is great, and escaping the variable after using (int) IS redundant, though I don't think it should cause an error. Quote Link to comment Share on other sites More sharing options...
raptor30506090 Posted April 10, 2012 Author Share Posted April 10, 2012 Hi all thank you for your help yes jesirose that the paganation link iv tryed the above with no luck still getting the same 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 '' at line 1 SELECT * FROM Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 10, 2012 Share Posted April 10, 2012 As was said above, there's no way that code can produce that error. Post the code for the page with any changes you've made since you said you tried suggestions. Quote Link to comment Share on other sites More sharing options...
raptor30506090 Posted April 10, 2012 Author Share Posted April 10, 2012 Hi here is the new code if(isset($_GET['subid'])){ $id = $_GET['subid']; } $id = (int) $id; $sql = "SELECT * FROM sub_nav WHERE subNav_ID = {$id}"; $query = mysql_query($sql); if(!$query) { die("Query: {$sql}<br>Error: " . mysql_error()); } $row = mysql_fetch_assoc($query); $table = strtolower($row['subNavName']); // ******************************* This if statment controls the content ************************ if($row['show_hide'] == 1){ $per_page = 2; $pages_query = mysql_query("SELECT COUNT('id') FROM textiles"); $pages = ceil(mysql_result($pages_query, 0) / $per_page); $page = (isset($_GET['p']) AND (int)$_GET['p'] > 0) ? (int)$_GET['p'] : 1; $start = ($page-1) * $per_page; $query = mysql_query("SELECT imageName FROM textiles LIMIT $start, $per_page"); while ($query_row = mysql_fetch_assoc($query)){ echo '<p>',$query_row['imageName'] , '</p>'; } if ($pages >= 1){ for($x=1; $x<=$pages; $x++){ echo '<a href="?p='.$x.'">'.$x.'</a> '; } } } Thank you Quote Link to comment Share on other sites More sharing options...
raptor30506090 Posted April 10, 2012 Author Share Posted April 10, 2012 still nedd help guys thanks Quote Link to comment Share on other sites More sharing options...
xyph Posted April 10, 2012 Share Posted April 10, 2012 Can you copy and paste the error directly? With the 'Query: ' and 'Error: ' strings included? It's odd your query is being truncated to SELECT * FROM, if that's indeed what's happening. Also, don't bump your threads until they've dropped off the first page, it's against the rules and will discourage help. We find it rude and selfish. Quote Link to comment Share on other sites More sharing options...
raptor30506090 Posted April 10, 2012 Author Share Posted April 10, 2012 ok this incudes the else <?php if(isset($_GET['subid'])){ $id = $_GET['subid']; } $id = (int) $id; $sql = "SELECT * FROM sub_nav WHERE subNav_ID = {$id}"; $query = mysql_query($sql); if(!$query) { die("Query: {$sql}<br>Error: " . mysql_error()); } $row = mysql_fetch_assoc($query); $table = strtolower($row['subNavName']); // ******************************* This if statment controls the content ************************ if($row['show_hide'] == 1){ $per_page = 2; $pages_query = mysql_query("SELECT COUNT('id') FROM textiles"); $pages = ceil(mysql_result($pages_query, 0) / $per_page); $page = (isset($_GET['p']) AND (int)$_GET['p'] > 0) ? (int)$_GET['p'] : 1; $start = ($page-1) * $per_page; $query = mysql_query("SELECT imageName FROM textiles LIMIT $start, $per_page"); while ($query_row = mysql_fetch_assoc($query)){ echo '<p>',$query_row['imageName'] , '</p>'; } if ($pages >= 1){ for($x=1; $x<=$pages; $x++){ echo '<a href="?p='.$x.'">'.$x.'</a> '; } } }else{ if(isset($_GET['subid'])){ $id = $_GET['subid']; } $query = mysql_query("SELECT * FROM sub_nav WHERE subNav_ID=" . (int)$id); $row = mysql_fetch_assoc($query); $table = strtolower($row['subNavName']); $sql = "SELECT * FROM $table"; $query = mysql_query($sql) or die(mysql_error() . '<br />' . $sql); $row = mysql_fetch_assoc($query); echo '<p>'.$row['content'].'</p>'; } ?> hope this helps if i remove the else then it returns nothing Thanks guys and girls Quote Link to comment Share on other sites More sharing options...
xyph Posted April 10, 2012 Share Posted April 10, 2012 $table is undefined. You need to make sure your data contains what you expect (or even exists) before using it in a query. You should code with error reporting set to -1. See my signature. Your code would have generated at the very least an undefined index notice. Quote Link to comment Share on other sites More sharing options...
raptor30506090 Posted April 10, 2012 Author Share Posted April 10, 2012 Hi this is what im getting 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 '' at line 1 SELECT * FROM Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 10, 2012 Share Posted April 10, 2012 $table is undefined. You need to make sure your data contains what you expect (or even exists) before using it in a query. You should code with error reporting set to -1. See my signature. Your code would have generated at the very least an undefined index notice. Quote Link to comment Share on other sites More sharing options...
raptor30506090 Posted April 10, 2012 Author Share Posted April 10, 2012 Hi all thanks for your help its not the Pagination part thats going wrong im going to have to have a re think on how to do this thanks again Quote Link to comment Share on other sites More sharing options...
raptor30506090 Posted April 10, 2012 Author Share Posted April 10, 2012 Hi jesirose Yes i can see what the problem is now thanks for your help im going to have a re think on how to do this Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.