nathanmaxsonadil Posted August 15, 2007 Share Posted August 15, 2007 Do you know what's wrong with my code? when I have valid id in the location bar it says "We looked everywhere but we can't find what your looking for..." Here's my code if($GET['id'] !== '') { echo '<div id="content"><div id="columnA">'; //Lets connect to MySQL mysql_connect ("localhost", "my_user", "my_pass") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("my_db"); $query = mysql_query("SELECT * FROM `news` WHERE id='" . $GET['id'] . "'") or die(mysql_error()); if (mysql_num_rows($query) == 0) { echo "<div id='post'><h2>We can't find anything</h2> <p>We looked everywhere but we can't find what your looking for<br/>Why dont you go to the blog homepage and see if it's there!</p></div>"; } while($r = mysql_fetch_assoc($query)) { echo "<div id='post'><h2><a href='?id={$r['id']}'>{$r['title']}</a></h2> <p>{$r['content']}</p></div> <div id='meta'><p>By: {$r['author']} at {$r['date']}</p></div><br/>"; } echo '</div>'; }else { echo '<div id="content"><div id="columnA">'; //Lets connect to MySQL mysql_connect ("localhost", "my_user", "my_pass") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("my_db"); $query = mysql_query("SELECT * FROM `news` ORDER BY `id` DESC LIMIT 10") or die(mysql_error()); if (mysql_num_rows($query) == 0) { echo "<div id='post'><h2>Nothing to display</h2> <p>Sorry we don't have anything to display.<br/>Suscribe to our <a href='http://swapinvites.com/feednews'>rss</a> feed for updates!</p></div>"; } while($r = mysql_fetch_assoc($query)) { echo "<div id='post'><h2><a href='?id={$r['id']}'>{$r['title']}</a></h2> <p>{$r['content']}</p></div> <div id='meta'><p>By: {$r['author']} at {$r['date']}</p></div><br/>"; } echo '</div>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/64987-solved-get-varible/ Share on other sites More sharing options...
Fadion Posted August 15, 2007 Share Posted August 15, 2007 shouldnt it be $_GET instead of $GET ?? Quote Link to comment https://forums.phpfreaks.com/topic/64987-solved-get-varible/#findComment-324355 Share on other sites More sharing options...
keeB Posted August 15, 2007 Share Posted August 15, 2007 $debug = true; if($debug) { echo "Debug mode entered.. <br>"; echo "Printing out page specific variables<br><pre>"; print_r($_GET); } When you're satisfied with $_GET output, set $debug to false, and the page should load as normal Quote Link to comment https://forums.phpfreaks.com/topic/64987-solved-get-varible/#findComment-324385 Share on other sites More sharing options...
nathanmaxsonadil Posted August 15, 2007 Author Share Posted August 15, 2007 the variable's is right but It's think there's no post in the mysql table that has that id Quote Link to comment https://forums.phpfreaks.com/topic/64987-solved-get-varible/#findComment-324753 Share on other sites More sharing options...
nathanmaxsonadil Posted August 15, 2007 Author Share Posted August 15, 2007 can anyone help me ??? Quote Link to comment https://forums.phpfreaks.com/topic/64987-solved-get-varible/#findComment-324848 Share on other sites More sharing options...
lemmin Posted August 15, 2007 Share Posted August 15, 2007 You should probably print out $_GET['id'] before your query and check it against what is in the table. Quote Link to comment https://forums.phpfreaks.com/topic/64987-solved-get-varible/#findComment-324853 Share on other sites More sharing options...
nathanmaxsonadil Posted August 15, 2007 Author Share Posted August 15, 2007 I echo'ed $_GET['id'] and it returend the right id is my query wrong? Quote Link to comment https://forums.phpfreaks.com/topic/64987-solved-get-varible/#findComment-324873 Share on other sites More sharing options...
lemmin Posted August 15, 2007 Share Posted August 15, 2007 Did you change your query to use $_GET['id'] instead of $GET['id']? Make sure whatever you are echoing out is the same variable that is in the query. Quote Link to comment https://forums.phpfreaks.com/topic/64987-solved-get-varible/#findComment-324877 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.