Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
If ID does not exist, display a custom error
Old 08-28-2010, 01:11 PM If ID does not exist, display a custom error
Experienced Talker

Posts: 32
Name: Kleidi
Trades: 0
Hello there,
I'm playing around (again :P ) with my article script that i'm creating but i'm blocked somewhere. I have the display page that checks if and ID is queried, if yes, displays the article that correspond with that id, if not, displays all the article page with the last articles added. But, what's happens if the ID queried does not exist? It mess up the page and does not display any error. What i need to do is an if statement to check first of all if the id exists and then display it, and if the id does not exist, to appear a "Article does not exist" message on the page.
Also, in the article db i have a table that stores if the article should be active or not for the visitors. In the mysql statement i have "Where Active=Yes" (LajmeAktiv='PO') and the visitors can see only the active articles, but, when a visitor changes the id on the URL manually and puts there an article id that is inactive, the article is shown . How to prevent this? I need to do something than, when a visitor tried to access an article that is inactive (Where LajmeAktiv='JO'), to appear a message on the page that tells the user that the id is looking for is inactive, or has no access to show it.
Can you PLEASE help me on this complicated think for me? Please!

My code:
PHP Code:
<?php
session_start
();
include(
"functions/functions.php");
include(
'functions/dbconn.php');
include(
'koka.php');
 
                if(isset (
$_GET['lajmeid'])) {

  
    
$lajmeid intval($_GET['lajmeid']); //make sure its an integer
   // $sql="SELECT B.katemri, A.id AS prodid, A.prodimg AS prodimg, A.prodinfo AS prodinfo, A.prodemri AS prodemri FROM p_produkte A LEFT JOIN p_kategori B ON A.katid = B.id WHERE B.id = ".$catId;
    
$sql "SELECT B.LKatEmri, A.LajmeID AS LajmeID, A.LajmeEmri AS LajmeEmri, A.LajmeLink AS LajmeLink, A.LajmeIntro AS LajmeIntro, A.LajmeTxt AS LajmeTxt, A.LajmeTag AS LajmeTag, A.LajmeImg AS LajmeImg, A.LajmeVideo AS LajmeVideo, A.LajmeAktiv AS LajmeAktiv, A.KatLajmeID AS KatLajmeID FROM lajme A LEFT JOIN lajme_kategori B ON A.KatLajmeID = B.LKatID WHERE B.LKatID = KatLajmeID AND A.LajmeID='$lajmeid' AND A.LajmeAktiv='PO'";
    

    
$result=mysql_query($sql);
        if(
mysql_num_rows($result) > 0//products found
    
{
        while(
$row mysql_fetch_assoc($result)) //Loop through the procusts and display them
        
{
     
?>
<body>
<div class="trupi">

<?php include('koka1.php'); ?>
<?php 
include('koka2.php'); ?>
    
    <div class="indexqender">
        <div class="trupimajtas">
            <div class="lajmehot">Lajmi fundit - HOT</div>
            <div class="lajmetqender">
                <div id="kokakuqe"> <p>Informohu! Eshte e drejta jote...</p></div>
                <div class="menupkokakuqe"><h1><?php echo $row['LKatEmri']; ?> - <?php echo $row['LajmeEmri']; ?></h1></div>
                
                
              
     <div class="artikullqender">
         <div class="artikulllajmi">
                       
             <h3> <?php echo $row['LajmeIntro']; ?></h3>
           
             <div class="teksti"> <img src="imazhet/artikuj/<?php echo $row['LajmeImg']; ?>" width="250" height="200" border="0" vspace="3" hspace="5" align="right" alt="<?php echo $row['LajmeEmri']; ?>" title="<?php echo $row['LajmeEmri']; ?>" />  <?php echo $row['LajmeTxt']; ?> </div>
             <div class="video"> <?php echo $row['LajmeVideo']; ?> </div>
             
            
              
             <div class="tag">Fjalët Kyçe:  <?php echo $row['LajmeTag']; ?></div>
             
             
            <?php
                     
}
                  }
                  
              }
                else{  
// Nese nuk eshte marre asnje id lajmi shfaqet si me poshte    ?>
                    
                    <body>
<div class="trupi">

<?php include('koka1.php'); ?>
<?php 
include('koka2.php'); ?>
    
    <div class="indexqender">
        <div class="trupimajtas">
            <div class="lajmehot">Lajmi fundit - HOT</div>
            <div class="lajmetqender">
                <div id="kokakuqe"> <p>Informohu! Eshte e drejta jote...</p></div>
                <div class="menupkokakuqe">Artikujt e fundit</div>
                
                
              
     <div class="artikullqender">
         <div class="artikulllajmi">
             
             <?php 
             
echo lajmetfundit ();
                } 
//Mbyllet else
             
?>
         </div>  
         
         <div class="artikulllajmidjathtas">
            <div class="menu">
                <ul>
                    <li><a href="#">List Item 1</a></li>
                    <li><a href="#">List Item 1</a></li>
                    <li><a href="#">List Item 1</a></li>
                    <li><a href="#">List Item 1</a></li>
                    <li><a href="#">List Item 1</a></li>  
                    
                </ul>

            </div>
         </div>
    </div>      
                <div class="pastro"></div>
                <div class="bllokposhtelajme"> Bllok poshte lajmeve</div>
                
            </div>
        </div>
        
        <div class="trupidjathtas">
            <div class="bllokd">
                <div class="bllokdtitulli">Parashikimi Motit </div>
                <div class="bllokdcontent">
                    <div class="bllokdcontenttxt">
                        <img src="http://l.yimg.com/a/i/us/we/52/<?=$currentImage;?>.gif" align="right" />
                        Temperatura: <?=$currentTemperature;?>&deg;C <br />
                        Me e larta: <?=$currentHigh;?>&deg;C<br />
                        Me e ulta: <?=$currentLow;?>&deg;C<br />
                        Lindja Djellit: <?=$currentSunrise;?><br />
                        Perendimi Djellit: <?=$currentSunset;?><br />
                        
                    </div><div class="pastro"></div>
                </div>
            </div>
            
            
            <div class="bllokd" style="margin-top:5px">
                <div class="bllokdtitulli">Kembimi Valutor </div>
                <div class="bllokdcontent">
                    <div class="bllokdcontenttxt"><center><p>
                       <img src="imazhet/ikona/ikona_europe.jpg" width="30" align="left" hspace="3" /><b>Euro - </b> <?php echo kv_euro (); ?> Lek</p>
                       <p><img src="imazhet/ikona/ikona_usa.gif" width="30" align="left" hspace="3" /><b>USD - </b> <?php echo kv_dollare (); ?> Lek</p>
                       <p><img src="imazhet/ikona/ikona_angli.gif" width="30" align="left" hspace="3" /><b>GBP - </b> <?php echo kv_gbp (); ?> Lek </p>
                        </center>
                    </div><div class="pastro"></div>
                </div>
            </div>
            <?php
            
echo reklama_2 (); // Shfaq reklama te rastesishm ne te djathte.
            
include('includet/rss.php');
            
?>
            
        </div>
    </div>
    </div>
<?php
include('fundi.php');
?>
Thank you in advance

P.S. JO=No and PO=Yes
Kleidi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-18-2010, 06:17 AM Re: If ID does not exist, display a custom error
Experienced Talker

Posts: 32
Name: Kleidi
Trades: 0
Any help?
Kleidi is offline
Reply With Quote
View Public Profile
 
Old 09-18-2010, 06:43 AM Re: If ID does not exist, display a custom error
Ultra Talker

Posts: 366
Name: Steve
Location: Miami, FL, Earth
Trades: 0
Change this:

PHP Code:
            <?php
                     
}
                  }
                  
              }
                else{  
// Nese nuk eshte marre asnje id lajmi shfaqet si me poshte    ?>
to this:
PHP Code:
            <?php
                     
}
                  } else {
                      print(
"<body><p>Warning: invalid id specified</p>");
                  }
                  
              }
                else{  
// Nese nuk eshte marre asnje id lajmi shfaqet si me poshte    ?>
__________________
- Steve

President,
Please login or register to view this content. Registration is FREE
smoseley is offline
Reply With Quote
View Public Profile Visit smoseley's homepage!
 
Old 09-18-2010, 06:45 AM Re: If ID does not exist, display a custom error
Ultra Talker

Posts: 366
Name: Steve
Location: Miami, FL, Earth
Trades: 0
And another tip: never program in any language other than English. It's the standard for the world.
__________________
- Steve

President,
Please login or register to view this content. Registration is FREE
smoseley is offline
Reply With Quote
View Public Profile Visit smoseley's homepage!
 
Old 09-18-2010, 07:58 AM Re: If ID does not exist, display a custom error
Experienced Talker

Posts: 32
Name: Kleidi
Trades: 0
Thank you very very much smoseley. It was very helpful since i was looking for this tip for many many days.

About language used: I know but some words in english does not correspond too good with my needs in my english. Anyway, i use english as much as i can since many technical terms i understand only in english...it's the standard language for the world.

Thank you again and wish you the best
Kleidi is offline
Reply With Quote
View Public Profile
 
Old 09-18-2010, 08:14 AM Re: If ID does not exist, display a custom error
Ultra Talker

Posts: 366
Name: Steve
Location: Miami, FL, Earth
Trades: 0
kleidi, that's not what I mean.

If any other programmer ever has to review your code, if you don't use English for variable names, function names, comments, etc... they'll have to figure everything out by examining every line of code. No good if you want to work with a team or contribute to OS projects.
__________________
- Steve

President,
Please login or register to view this content. Registration is FREE
smoseley is offline
Reply With Quote
View Public Profile Visit smoseley's homepage!
 
Old 09-18-2010, 01:48 PM Re: If ID does not exist, display a custom error
Experienced Talker

Posts: 32
Name: Kleidi
Trades: 0
Aham...got the idea. Since i work alone to my projects, i didn't thought that this will be difficult to understand by others. I'll try to make in english from now.

Thanks for helping me
Kleidi is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to If ID does not exist, display a custom error
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25601 seconds with 12 queries