#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0

    Unexpected reason for error- Data to render this page is missing.


    The code below produces "Data to render this page is missing."
    This was written in this block but I can't find the reason. The database is set up, I have other pages pulling from it, but I'm not finding a reason for it to produce this error

    PHP Code:
    // Check to see the URL variable is set and that it exists in the database
    if (isset($_GET['id'])) {
        
    // Connect to the MySQL database 
        
    include "storescripts/connect_to_mysql.php";
        
    // Use this var to check to see if this ID exists, if yes then get the product
        // details, if no then exit this script and give message why
        
    $id preg_replace('#[^0-9]#i'''$_GET['id']);
        
    $sql mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1");
        
    $productCount mysql_num_rows($sql); // count the output amount
        
    if ($productCount 0) {
            
    // get all the product details
            
    while($row mysql_fetch_array($sql)){
                 
    $id $row["id"];
                 
    $product_name $row["product_name"];
                 
    $price $row["price"];
                 
    $details $row["details"];
                 
    $category $row["category"];
                 
    $subcategory $row["subcategory"];
                 
    $date_added strftime("%b %d, %Y"strtotime($row["date_added"]));
             }
             
        } else {
                echo 
    "That item does not exist.";
                exit();
            }
            
    } else {
        echo 
    "Data to render this page is missing.";
        exit();
    }
    mysql_close(); 
  2. #2
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,110
    Rep Power
    4103
    If that is the error you are getting, it means you are not passing an id parameter in the URL, resulting in your isset($_GET['id']) check failing
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,350
    Rep Power
    630
    It seems pretty straight forward to me. The value of $_GET['id'] is not set. Print the URL to see if it contains what you expect.

    P.S. Immediately get rid of the deprecated MySQL extentions and switch to PDO.

    Comments on this post

    • Jacques1 agrees
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    5
    Rep Power
    0
    I added this:
    PHP Code:
    $id $_GET['id']; 
    but I still get the error.
    I'm new to PHP and have been following a tutorial, if you could write out how to set the variable like it should be it would be a great help.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,350
    Rep Power
    630
    Get a new tutorial. That it uses MySQL extensions that have been deprecated for more than a decade is telling. Setting a variable to an unset variable does nothing. Add this in front of your first 'if'.
    PHP Code:
    echo "<pre>";
    print_r($_GET);
    echo 
    "</pre>";
    echo 
    "<br>$_SERVER['HTTP_REFERER']"
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1017
    Originally Posted by 1v4n
    I'm new to PHP and have been following a tutorial, if you could write out how to set the variable like it should be it would be a great help.
    You don't understand. The problem is that there is no "id" parameter in the URL. This is not an application fault, it's simply an incomplete URL.

    You need something like this:

    Code:
    https://yoursite.com/yourscript.php?id=123
    The only question is: Why is that parameter missing? Did you forget it? Was the link generated by a faulty script?
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,082
    Rep Power
    379
    Originally Posted by gw1500se
    P.S. Immediately get rid of the deprecated MySQL extentions and switch to PDO.
    i think one Jacques is enough thank you

    Comments on this post

    • gw1500se disagrees : Apparently not as OPs tend to ignore multiple suggestions to cease and decist.

IMN logo majestic logo threadwatch logo seochat tools logo