djuke1 Posted July 13, 2011 Share Posted July 13, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241876-undefined-variable-help/ Share on other sites More sharing options...
djlee Posted July 13, 2011 Share Posted July 13, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241876-undefined-variable-help/#findComment-1242132 Share on other sites More sharing options...
djuke1 Posted July 13, 2011 Author Share Posted July 13, 2011 here is my inventory list incase that helps http://pastebin.com/vK8wgeUu but i will try that thanks Quote Link to comment https://forums.phpfreaks.com/topic/241876-undefined-variable-help/#findComment-1242139 Share on other sites More sharing options...
djuke1 Posted July 13, 2011 Author Share Posted July 13, 2011 Here are his source files i cant seem to find a difference between his and mine [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/241876-undefined-variable-help/#findComment-1242140 Share on other sites More sharing options...
djuke1 Posted July 13, 2011 Author Share Posted July 13, 2011 ok inventory list works but it gives me another error "Notice: Undefined variable: product_list in /home/a7064593/public_html/storeadmin/inventory_edit.php on line 63" and line 63 is the added piece of code Quote Link to comment https://forums.phpfreaks.com/topic/241876-undefined-variable-help/#findComment-1242144 Share on other sites More sharing options...
djlee Posted July 13, 2011 Share Posted July 13, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241876-undefined-variable-help/#findComment-1242170 Share on other sites More sharing options...
bibibrazil Posted October 6, 2011 Share Posted October 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241876-undefined-variable-help/#findComment-1276428 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.