[HELP] not sure what the title should be..

Status
Not open for further replies.

Sledmore

Chaturbate Livestreamer
Staff member
FindRetros Moderator
Jul 24, 2010
5,195
3,906
Hey,

Er, I've coded part of a news system, And it works like /news?id=1 - How would I make this say, "Article not found!" ?

- Thanks.
 

Dayron1234

Rapnameiszero,cuzIhavezero,toleranceforidiots
Jun 30, 2010
772
35
So you want it to make it get an error?

EDIT:
This what your looking for?

PHP:
<?php
if (some coding here)
{
die("Article not found!");
}
else
{
//some coding here
}
?>
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
PHP:
$id = $_GET['id'];
$query = MySQL_query("SELECT * FROM news WHERE id='$id'") or die("article not found");
I haven't tested this, but I'm pretty sure that's how it should be, anyways. Let me know if it worked.
 
Nov 23, 2010
307
2
PHP:
<?php
$id = $_POST['id']; // or $_GET['id']
$sql = mysql_query("SELECT * FROM news WHERE id = $id");
require('./config.php');
if($sql) {
if($row = mysql_fetch_array($sql)) {
echo " " . $row['title'] . "<br><br>";
echo " " . $row['story'] . "<br><br>";
echo " " . $row['author'] . "<br><br><br>";
}
else {
?>
<font color="red"><b>Article not found</b></font>
<?php  } } ?>

isnt tested , hope this works!

@obrienray1
i dont think that sledy dont know this , i guess he needs one with mysql etc. that is full

EDIT : This is tested and it works :)!
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
This should work:

PHP:
<?php
$news_id = mysql_real_escape(strip_tags( $_GET['id'] ) );
if( !$news_id )
{
    echo 'No News article selected!';
}
else
{
    $check = mysql_query( "SELECT * FROM news_articles WHERE `id` = '$news_id'" );
    if( mysql_num_rows( $check ) == 0 ) //article not found/doesn't exist
    {
        echo 'This news article does not exist!';
    }
    else
    {
        $n = mysql_fetch_array( $check ); //get all rows from the news article
        echo '<h1>' . $n["title"] . '</h1><p>' . $n["content"] . '</p>';
    }
}
?>
 
Nov 23, 2010
307
2
This should work:

PHP:
<?php
$news_id = mysql_real_escape(strip_tags( $_GET['id'] ) );
if( !$news_id )
{
    echo 'No News article selected!';
}
else
{
    $check = mysql_query( "SELECT * FROM news_articles WHERE `id` = '$news_id'" );
    if( mysql_num_rows( $check ) == 0 ) //article not found/doesn't exist
        echo 'This news article does not exist!';
    }
    else
    {
        $n = mysql_fetch_array( $check ); //get all rows from the news article
        echo '<h1>' . $n["title"] . '</h1><p>' . $n["content"] . '</p>';
    }
}
?>

there is much easier way that works same as this , anyways why is needed the last "}" in PHP code , it ends nothing !
 
Nov 23, 2010
307
2
No ?
PHP:
<?php
$news_id = mysql_real_escape(strip_tags( $_GET['id'] ) );
if( !$news_id )
{ //starts
    echo 'No News article selected!';
} //ends
else
{ // starts
    $check = mysql_query( "SELECT * FROM news_articles WHERE `id` = '$news_id'" );
    if( mysql_num_rows( $check ) == 0 ) //article not found/doesn't exist
        echo 'This news article does not exist!';
    } // ends
    else
    { //start
        $n = mysql_fetch_array( $check ); //get all rows from the news article
        echo '<h1>' . $n["title"] . '</h1><p>' . $n["content"] . '</p>';
    } //ends
} // nothing ?!
?>
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
I'm sorry but are you thick?
If you miss out that last bracket, PHP will throw an error - it needs to end the If statement, there is no end it it.
PHP:
}
else
{
is just a tidier way of doing
PHP:
}else{
There's no difference so if you don't have the '}' connecting to the '{' PHP will automatically throw an error.

I know what I'm doing, I've been doing PHP for just over a year, I'm sure I know how to program an If statement...
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
No ?
PHP:
<?php
$news_id = mysql_real_escape(strip_tags( $_GET['id'] ) );
if( !$news_id )
{ //starts
    echo 'No News article selected!';
} //ends
else
{ // starts
    $check = mysql_query( "SELECT * FROM news_articles WHERE `id` = '$news_id'" );
    if( mysql_num_rows( $check ) == 0 ) //article not found/doesn't exist
        echo 'This news article does not exist!';
    } // ends
    else
    { //start
        $n = mysql_fetch_array( $check ); //get all rows from the news article
        echo '<h1>' . $n["title"] . '</h1><p>' . $n["content"] . '</p>';
    } //ends
} // nothing ?!
?>
Just to clear things out, that is wrong.
Way it is:
PHP:
<?php
$news_id = mysql_real_escape(strip_tags( $_GET['id'] ) );
if( !$news_id )
{ //starts
    echo 'No News article selected!';
} //ends
else
{ // starts
    $check = mysql_query( "SELECT * FROM news_articles WHERE `id` = '$news_id'" );
    if( mysql_num_rows( $check ) == 0 ) //article not found/doesn't exist
        [B] { [/B] //start
        echo 'This news article does not exist!';
    } // ends
    else
    { //start
        $n = mysql_fetch_array( $check ); //get all rows from the news article
        echo '<h1>' . $n["title"] . '</h1><p>' . $n["content"] . '</p>';
    } //ends
} [B] /*end*/ [/B]
?>

[mod] Threrad closed, if you want to reopen the thread @thread starter just PM me [/mod]
 
Status
Not open for further replies.

Users who are viewing this thread

Top