Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts

    Redirect user if Value Not found

    Hello

    this is My code , i need to edit to redierect the user to main page when the ID not Found . in the Mysql

    see if he type the url like : www.example.com/page?id=33

    Now if the ID 33 not found to redierect the user to index.php

    PHP Code:
    // connect here
    $data mysql_query("SELECT * FROM ".$DB->prefix("pages")." WHERE id='$id'") or die(mysql_error());
    //Puts it into an array
    while($info mysql_fetch_array$data ))
    {
    Echo 
    "<b>page:</b> ".$info['page'] . "<br> ";
    Echo 
    "<b>url:</b> ".$info['url'] . "<br> ";
    Echo 
    "<b>name:</b> ".$info['name'] . "<br> ";


  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    PHP Code:
    $data mysql_query("SELECT * FROM ".$DB->prefix("pages")." WHERE id='$id'") or die(mysql_error()); 
    if(
    mysql_num_rows($result) == 0) {
        
    header('Location: /index.php');
        exit();
    }
    //Puts it into an array 
    while($info mysql_fetch_array$data )) 

    Echo 
    "<b>page:</b> ".$info['page'] . "<br> "
    Echo 
    "<b>url:</b> ".$info['url'] . "<br> "
    Echo 
    "<b>name:</b> ".$info['name'] . "<br> "

    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • Users who have thanked JAY6390 for this post:

    ajloun (01-19-2010)

  • #3
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Thank you , working great ..

    PHP Code:
    if(mysql_num_rows($result) == 0) { 
    to
    PHP Code:
    if(mysql_num_rows($data) == 0) { 

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Oops it's getting late. Glad you understood what I meant
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •