Jump to content

Recommended Posts

I am following this tutorial here http://youtu.be/WrbaISEEihM. When i try to edit a product in my inventory i get an error "Undefined variable: product_list in /home/a7064593/public_html/storeadmin/inventory_edit.php on line 85" and i cant work out how to fix it. here is my code http://pastebin.com/k36tBjEL.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/241876-undefined-variable-help/
Share on other sites

i cant see the video, but basically, an undefined variable means exactly that. Theres no hidden secrets. Your trying to use a variable that hasnt been defined. Looking at your code you do not create and assign a value to that variable anywhere.

 

The product list looks like it should be a variable containing the html to be outputted into the list. I suggest you go back through the video and find out where this is defined and how. the product list will most likely be defined above the while loop and then appended to within the while loop with each product.

 

change

// Gather this product's full information for inserting automatically into the edit form below on page
if (isset($_GET['pid'])) {
        $targetID = $_GET['pid'];
    $sql = mysql_query("SELECT * FROM products WHERE id='$targetID' LIMIT 1");
    $productCount = mysql_num_rows($sql); // count the output amount
    if ($productCount > 0) {
            while($row = mysql_fetch_array($sql)){
             
                         $product_name = $row["product_name"];
                         $price = $row["price"];
                         $category = $row["category"];
                         $subcategory = $row["subcategory"];
                         $details = $row["details"];
                         $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
        }
    } else {
            echo "Sorry dude that crap dont exist.";
                exit();
    }
}

 

to

// Gather this product's full information for inserting automatically into the edit form below on page
if (isset($_GET['pid'])) {
  
     $product_list = "";
        $targetID = $_GET['pid'];
    $sql = mysql_query("SELECT * FROM products WHERE id='$targetID' LIMIT 1");
    $productCount = mysql_num_rows($sql); // count the output amount
    if ($productCount > 0) {

            while($row = mysql_fetch_array($sql)){
             
                         $product_name = $row["product_name"];
                         $price = $row["price"];
                         $category = $row["category"];
                         $subcategory = $row["subcategory"];
                         $details = $row["details"];
                         $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
   
                        $product_list .= $row["product_name"]."<br />";

        }
    } else {
            echo "Sorry dude that crap dont exist.";
                exit();
    }
}

 

to see what i mean

his source files are wrong, product_list isnt defined anywhere, so either he has shared the wrong files or he never actually successfully finished what he was doing. I've given you an example of how to "do this yourself". product list seems to just be the html output. So within the while loop that gets the products, just keep adding to a product_list variable, the html output yoyu want to see

  • 2 months later...

I can't be sure that the source are "wrong" maybe there is another way

to work that great Script thatt Adam Khoury wrotte :)

anyway this is what I've just done today

(it seems to be a good work arround... more verifying is required though.)

 

Added the folowing line.

$details = $row["details"];

$product_list = "";

 

Results:

1) Database seems to update fine !

2) There is no more error message too.

Happy coding !!!

Eric

  :P

 

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.