Jump to content

Recommended Posts

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>';
}
}

Link to comment
https://forums.phpfreaks.com/topic/64987-solved-get-varible/
Share on other sites

$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 :)

Link to comment
https://forums.phpfreaks.com/topic/64987-solved-get-varible/#findComment-324385
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.