rootKID Posted May 26, 2012 Share Posted May 26, 2012 (edited) Hello W3schools again, a problem has been showed up on my little shop project again, and some people in here might knows it still... anyways... the people that tried to help me, if you are one of them. please read on... else, well... just read ... anyways... i went to my school teacher (one of them) and asked for help, and we did solve it with some big issues he told me and pointed out for me... and that was a big help for the understanding...anyways. i came home... and now the weird part is comming... when im trying to add somfthing to my shop (the cart/session)... then its like it just wont listen, because the fun part is that it (DOES) redirects do shop.php as i told it to do in the function that i call to add the redirect... that... orr its just updating.. but seems like it redirects... anyways... here are the files of my related to the shop: (ATTACHED) and i must say, i dont really knows how to explain this... since it would be impossible to redirect without the function, and that i cannot see either on the URL... :/...so please tell me if you need more information on anything... dont knows what to tell... (NO PAGE ERRORS...) so i cannot really answer anymore questions on this problem unless you are asking me ... Hoping answers soon... Regards: rootKID EDIT: Note that the details page its just a beginning... but thinked that it would be ok to add it just in case you was wonder... lol ... Edited May 26, 2012 by rootKID 2 Link to comment Share on other sites More sharing options...
justsomeguy Posted May 26, 2012 Share Posted May 26, 2012 You'll probably get more help if you post your code instead of attaching files for people to download. But first I would suggest adding this to the top of each page and see if it changes anything: ini_set('display_errors', 1);error_reporting(E_ALL); Link to comment Share on other sites More sharing options...
rootKID Posted May 27, 2012 Author Share Posted May 27, 2012 (edited) sorry for late reply, i will try right away... thanks ... Posting feedback in a momment ... EDIT: hmm... weird... its giving me these errors below: (ATTACHED)... and here is the shop.php code you did ask for...: <?phpinclude ("include/config.php");include ("include/database.php");session_start();ob_start();ini_set('display_errors', 1);error_reporting(E_ALL);?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><link rel="stylesheet" href="styles/1.css" type="text/css" /><link rel='shortcut icon' href='fav_icon.ico' /><title><?php echo $sitename; ?></title></head><body> <center><div id="header"><?php include ("banner.php"); ?></div></center> <center><div id="status_bar"><!--STATUS BAR--><div class="status_left"><?php include ("status_left.php"); ?></div><!--/********************/--><div class="status_right"><?php include ("status_right.php"); ?></div></div><!--STATUS BAR--></center> <center><div id="menu"><?php include ("menu.php"); ?></div></center> <center><div id="content_body"><!--/**********************/--><?phpecho "<pre>";print_r($_SESSION);echo "</pre>";include ("shop_categories.php");echo "<br />";$catID = $_GET['cat_id'];if($_GET['cat_id'] == ""){ $query = "SELECT * FROM shop_items"; $result = mysql_query($query)or die(mysql_error());}else { $query = "SELECT * FROM shop_items WHERE FK_catID = $catID"; $result = mysql_query($query)or die(mysql_error());} if(mysql_num_rows($result)>0)//Checking to see if there is any rows to take...{echo "<form action='' method='post'>";echo "<table class='shop_table_100'>";echo "<tr class='shop_tr_holder_css'>";echo "<td>Add</td>";echo "<td>Amount</td>";echo "<td>Product Name</td>";echo "<td>Price</td>";echo "<td>More Info</td>";echo "</tr>";while ($row = mysql_fetch_assoc($result)){echo "<tr>\n";echo "<td><input type='checkbox' name='check_addbox[".$row['item_id']."]' /></td>\n"; ////extra array...echo "<td><input type='text' name='amount[".$row['item_id']."]' size='1' value='1' /></td>\n"; //With extra array...echo "<td>".$row['item_name']."</td>\n";echo "<td>".$row['item_price']." USD</td>\n";echo "<td><a href='shop_details.php?item_id=".$row['item_id']."'>Info</a></td>\n";echo "</tr>\n";}echo "</table>";echo "</form>"; echo "<form action='' method='post'>";echo "<table class='shop_table_100'";echo "<tr>";echo "<td><input type='submit' name='add_item' id='submit' class='shop_add_submit_button' value='Update Cart' /></td>";echo "</tr>";echo "</table>";echo "</form>";}//Ending IF (Num_Rows...)else{echo "<form action='' method='post'>";echo "<table class='shop_table_100'>";echo "<tr class='shop_tr_holder_css'>";echo "<td>ERROR!</td>";echo "</tr>";echo "</table>";echo "</form>";echo "<form action='' method='post'>";echo "<table class='shop_table_100'>";echo "<tr>";echo "<td>There are no Products to show yet.</td>";echo "</tr>";echo "</table>";echo "</form>";} if(isset($_POST['add_item'])){if(!empty($_POST['check_addbox'])){ foreach($_POST['check_addbox'] as $p_id => $check) { $amount = $_POST['amount'][$p_id]; //Getting the Amount from the box... $_SESSION['cart'][$p_id] += $amount; //adding them to the session... header("location: shop.php"); }}}?><!--/**********************/--></div></center> <center><div id="footer"><?php include ("footer.php"); ?></div></center></body></html> and if its for any help, then here is my shop_categories.php code also: <?php$under_query = "SELECT * FROM shop_cat";$under_result = mysql_query($under_query)or die(mysql_error());if(mysql_num_rows($under_result)>0)//Checking to see if there is any rows to take...{while($u_row = mysql_fetch_assoc($under_result)){echo "<a href='shop.php?cat_id=".$u_row['shop_cat_id']."'>".$u_row['shop_cat_name']."</a> ";}}//If ends...else {echo "No categories to show yet.";}?> i dont know if i did answer this on the #1 post... but what my teacher did to help me, was that once you are entering the page, then it will show all the products i have... and if a category is setted, (THEN) it will show the product for that category... and that is working also... its just the adding to the cart part... :/... Edited May 27, 2012 by rootKID Link to comment Share on other sites More sharing options...
thescientist Posted May 27, 2012 Share Posted May 27, 2012 I could have sworn we went over this in your other post. the problem is you don't know if cat_id is set, so that's why you have to test it first.http://w3schools.invisionzone.com/index.php?showtopic=43401&st=20&p=240017entry240017 Link to comment Share on other sites More sharing options...
rootKID Posted May 27, 2012 Author Share Posted May 27, 2012 that is not the same i suppose... it stil dosent adding shop products to the cart, and the other did...the other was a problem to the output of the products when a category was not setted (NONE TO SHOW)... that is how i at least remember it ...but yes, i do agree... same error im getting... but still should not be a problem since this is for adding... and not showing... i suppose?... Link to comment Share on other sites More sharing options...
thescientist Posted May 27, 2012 Share Posted May 27, 2012 (edited) I guess so. You posted a picture with error messages. My response was to address those error messages. Maybe start by fixing those and see what your code does after that? Like in the other thread though, what debugging are you doing? You should have echo statements all over the place initially if you don't know why your code is working. echo every conditional, what the values of all your variables are, and see if they match what you expect them to be. The script is only going to do what you tell it to do, so make sure you are giving it the right instructions, and prove it by tracing your code's execution path. Edited May 27, 2012 by thescientist Link to comment Share on other sites More sharing options...
rootKID Posted May 28, 2012 Author Share Posted May 28, 2012 okay.i will try the thing you said tomorrow. and feedback.im not home right now, since overtime at job .but i still dont understand why, since the other did work X)... Link to comment Share on other sites More sharing options...
thescientist Posted May 28, 2012 Share Posted May 28, 2012 (edited) but i still dont understand why, since the other did work X)...welcome to world of development. the key in all projects is to start small, and work your way up in functionality piece by piece before moving on to the next. It usually takes lots of debugging and verification of the code through echos, loggins, unit tests, etc. It's something we all have to do everyday. Edited May 28, 2012 by thescientist Link to comment Share on other sites More sharing options...
rootKID Posted May 30, 2012 Author Share Posted May 30, 2012 (edited) hello again TST... i did as you told me to, and trying to echo everything all over the place to try see what did what...and this is my result: 1. i started to make a if statement like so: /*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/if(!$catID == ""){echo "Succes! [CAT_ID ECHO]";}else {echo "Noob! [CAT_ID ECHO]";}/*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/ to see what it gave me... and i got the noob on the screen... that means no ID, and then i tried just for fun, to make the if as a true (by removing this (!))...and i got a succes... i suppose that im getting a ID still somewhere from then... then i maked the same if statement in the category file that im including on shop.php... and echo the SQL im making. just to try what you said, and see if anything was of meaning by that sql... like so: /*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/if($under_query == ""){echo "Succes! [CAT_ID ECHO]";}else {echo "Noob! [CAT_ID ECHO]";}/*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/ and i got the noob from there... so i suppose that sql is the thing that is wrong... orr what?... 2. now i dont know what more to echo since i had that url, and 1 on shop... this is my shop.php file: echo "<pre>";print_r($_SESSION);echo "</pre>"; include ("shop_categories.php"); echo "<br />"; $catID = $_GET['cat_id'];if($_GET['cat_id'] == ""){ $query = "SELECT * FROM shop_items"; $result = mysql_query($query)or die(mysql_error());}else { $query = "SELECT * FROM shop_items WHERE FK_catID = $catID"; $result = mysql_query($query)or die(mysql_error());} /*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/if(!$catID == ""){echo "Succes! [CAT_ID ECHO]";}else {echo "Noob! [CAT_ID ECHO]";}/*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/ if(mysql_num_rows($result)>0)//Checking to see if there is any rows to take...{echo "<form action='' method='post'>";echo "<table class='shop_table_100'>";echo "<tr class='shop_tr_holder_css'>";echo "<td>Add</td>";echo "<td>Amount</td>";echo "<td>Product Name</td>";echo "<td>Price</td>";echo "<td>More Info</td>";echo "</tr>";while ($row = mysql_fetch_assoc($result)){echo "<tr>\n";echo "<td><input type='checkbox' name='check_addbox[".$row['item_id']."]' /></td>\n"; ////extra array...echo "<td><input type='text' name='amount[".$row['item_id']."]' size='1' value='1' /></td>\n"; //With extra array...echo "<td>".$row['item_name']."</td>\n";echo "<td>".$row['item_price']." USD</td>\n";echo "<td><a href='shop_details.php?item_id=".$row['item_id']."'>Info</a></td>\n";echo "</tr>\n";}echo "</table>";echo "</form>"; echo "<form action='' method='post'>";echo "<table class='shop_table_100'";echo "<tr>";echo "<td><input type='submit' name='add_item' id='submit' class='shop_add_submit_button' value='Update Cart' /></td>";echo "</tr>";echo "</table>";echo "</form>";}//Ending IF (Num_Rows...)else{echo "<form action='' method='post'>";echo "<table class='shop_table_100'>"; echo "<tr class='shop_tr_holder_css'>";echo "<td>ERROR!</td>";echo "</tr>"; echo "</table>";echo "</form>"; echo "<form action='' method='post'>";echo "<table class='shop_table_100'>"; echo "<tr>";echo "<td>There are no Products to show yet.</td>";echo "</tr>"; echo "</table>";echo "</form>";} if(isset($_POST['add_item'])){if(!empty($_POST['check_addbox'])){ foreach($_POST['check_addbox'] as $p_id => $check) { $amount = $_POST['amount'][$p_id]; //Getting the Amount from the box... [p_id] is indicating what product it is (the checkbox...) $_SESSION['cart'][$p_id] += $amount; //adding them to the session... header("location: shop.php"); }}} and this is my category file: $under_query = "SELECT * FROM shop_cat";$under_result = mysql_query($under_query)or die(mysql_error()); if(mysql_num_rows($under_result)>0)//Checking to see if there is any rows to take...{while($u_row = mysql_fetch_assoc($under_result)){echo "<a href='shop.php?cat_id=".$u_row['shop_cat_id']."'>".$u_row['shop_cat_name']."</a> ";}}//If ends...else {echo "No categories to show yet.";}/*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/if($under_query == ""){echo "Succes! [CAT_ID ECHO]";}else {echo "Noob! [CAT_ID ECHO]";}/*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/ so... what now? :/... i mean, what to do with the SQL... if i dont get a ID for the shop... then i suppose i cannot add it to the cart...or am i wrong? :/... Edited May 30, 2012 by rootKID Link to comment Share on other sites More sharing options...
justsomeguy Posted May 30, 2012 Share Posted May 30, 2012 This statement: if(!$catID == ""){ Is going to be true if $catID is not empty, and false if it is empty. You're converting $catID to a boolean with the ! operator and then testing it against an empty string. That means that if $catID is a number then it will be converted to a boolean true, and tested with an empty string which makes the if statement false. If you want to test if $catID is not an empty string then you do one of these: if ($catID != "")if (!($catID == "")) So since in your code it went into the else, then that means that $catID has a value. You can just print out the value directly to verify that. The other if statement where you're testing $under_query is basically useless, because you always set that variable to a non-empty value. The if statement will never be true. Link to comment Share on other sites More sharing options...
rootKID Posted May 30, 2012 Author Share Posted May 30, 2012 (edited) i see... but when i try to echo out the $catID... then i get nofthing... (PICTURE ATTACHED...) and i added this: echo $catID; right under the other (noob) echo...and yeah, i did knew about the ! on under_query... just did not explain that well i supose ... EDIT: so i must say... im clueless... i did as you said, and i dont see what to change since i do not get any value from the echo on catID... but still it tells me from the if that it does... or am i still wrong :/... Edited May 30, 2012 by rootKID Link to comment Share on other sites More sharing options...
justsomeguy Posted May 30, 2012 Share Posted May 30, 2012 The notices say that cat_id is an undefined index, so it sounds like it wasn't passed in the URL. Link to comment Share on other sites More sharing options...
rootKID Posted May 30, 2012 Author Share Posted May 30, 2012 (edited) true... it was not.. the teacher told me that he changed the code so instead of showing the categories from #1 when comming into shop when no id is given in the URL...then its showing all the products untill a ID is given... :X... EDIT: could it be the URL link im clicking on a product when trying to add and then running the wrong word?... Edited June 1, 2012 by rootKID Link to comment Share on other sites More sharing options...
birbal Posted June 6, 2012 Share Posted June 6, 2012 check the link you are clicking or just var_dump($_GET) in target page to see if that is there or not Link to comment Share on other sites More sharing options...
rootKID Posted June 6, 2012 Author Share Posted June 6, 2012 i was checking... but nofthing as far as i see... and same with the var.. here is the var: (PICTURE ADDED)... even true i tried adding a product again, then it still was on 0 in the (array (var))... but i did get a cat_id when i tried to enter a new category... and that part has allways worked... :/... Link to comment Share on other sites More sharing options...
birbal Posted June 6, 2012 Share Posted June 6, 2012 (edited) if($_GET['cat_id'] == "")should beif(isset($_GET['cat_id'])) it is checking now that $_GET['cat_id'] is empty string or not. when it has value it still checks for empty string and execute the else part. you should check $_GET['cat_id'] is set or not. http://php.net/isset Edited June 6, 2012 by birbal Link to comment Share on other sites More sharing options...
rootKID Posted June 6, 2012 Author Share Posted June 6, 2012 hmm... did... and now im getting more errors X)... picture attached...hmm... code below: if(isset($_GET['cat_id'])){ $query = "SELECT * FROM shop_items"; $result = mysql_query($query)or die(mysql_error());}else { $query = "SELECT * FROM shop_items WHERE FK_catID = $catID"; $result = mysql_query($query)or die(mysql_error());} Link to comment Share on other sites More sharing options...
justsomeguy Posted June 6, 2012 Share Posted June 6, 2012 At this point you probably need to post your entire code. You can also just copy and paste error messages, you don't need to make a screenshot every time. The code you posted above includes a call to isset at one point, but you're still trying to use a variable called $catID so you probably already accessed that before you used isset. Link to comment Share on other sites More sharing options...
rootKID Posted June 7, 2012 Author Share Posted June 7, 2012 sorry, will post later. i dont have the code at my school. feedback later... Link to comment Share on other sites More sharing options...
rootKID Posted June 7, 2012 Author Share Posted June 7, 2012 (edited) hello, im home now... here is the code from shop.php file: <?phpecho "<pre>";print_r($_SESSION);echo "</pre>"; include ("shop_categories.php"); echo "<br />";var_dump($_GET);$catID = $_GET['cat_id'];//if(isset($_GET['cat_id']))if($_GET['cat_id'] == ""){ $query = "SELECT * FROM shop_items"; $result = mysql_query($query)or die(mysql_error());}else { $query = "SELECT * FROM shop_items WHERE FK_catID = $catID"; $result = mysql_query($query)or die(mysql_error());} /*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/if(!$catID == ""){echo "Succes! [CAT_ID ECHO]";}else {echo "Noob! [CAT_ID ECHO]";}/*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/ echo $catID; if(mysql_num_rows($result)>0)//Checking to see if there is any rows to take...{echo "<form action='' method='post'>";echo "<table class='shop_table_100'>";echo "<tr class='shop_tr_holder_css'>";echo "<td>Add</td>";echo "<td>Amount</td>";echo "<td>Product Name</td>";echo "<td>Price</td>";echo "<td>More Info</td>";echo "</tr>";while ($row = mysql_fetch_assoc($result)){echo "<tr>\n";echo "<td><input type='checkbox' name='check_addbox[".$row['item_id']."]' /></td>\n"; ////extra array...echo "<td><input type='text' name='amount[".$row['item_id']."]' size='1' value='1' /></td>\n"; //With extra array...echo "<td>".$row['item_name']."</td>\n";echo "<td>".$row['item_price']." USD</td>\n";echo "<td><a href='shop_details.php?item_id=".$row['item_id']."'>Info</a></td>\n";echo "</tr>\n";}echo "</table>";echo "</form>"; echo "<form action='' method='post'>";echo "<table class='shop_table_100'";echo "<tr>";echo "<td><input type='submit' name='add_item' id='submit' class='shop_add_submit_button' value='Update Cart' /></td>";echo "</tr>";echo "</table>";echo "</form>"; }//Ending IF (Num_Rows...)else{echo "<form action='' method='post'>";echo "<table class='shop_table_100'>"; echo "<tr class='shop_tr_holder_css'>";echo "<td>ERROR!</td>";echo "</tr>"; echo "</table>";echo "</form>"; echo "<form action='' method='post'>";echo "<table class='shop_table_100'>"; echo "<tr>";echo "<td>There are no Products to show yet.</td>";echo "</tr>"; echo "</table>";echo "</form>";} if(isset($_POST['add_item'])){if(!empty($_POST['check_addbox'])){ foreach($_POST['check_addbox'] as $p_id => $check) { $amount = $_POST['amount'][$p_id]; //Getting the Amount from the box... [p_id] is indicating what product it is (the checkbox...) $_SESSION['cart'][$p_id] += $amount; //adding them to the session... header("location: shop.php"); }}}?> hope it helps ... here is code for categories file: <?php$under_query = "SELECT * FROM shop_cat";$under_result = mysql_query($under_query)or die(mysql_error());if(mysql_num_rows($under_result)>0)//Checking to see if there is any rows to take...{while($u_row = mysql_fetch_assoc($under_result)){echo "<a href='shop.php?cat_id=".$u_row['shop_cat_id']."'>".$u_row['shop_cat_name']."</a> ";}}//If ends...else {echo "No categories to show yet.";}/*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/if($under_query == ""){echo "Succes! [CAT_ID ECHO]";}else {echo "Noob! [CAT_ID ECHO]";}/*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/?> hope it helps ...and yeah, will be posting the errors with words instead of pics from now on ... Edited June 7, 2012 by rootKID Link to comment Share on other sites More sharing options...
birbal Posted June 7, 2012 Share Posted June 7, 2012 Where is the errors? //if(isset($_GET['cat_id']))you commented the isset() part. still issue is there same as i posted in the last post. is that your updated code? 1 Link to comment Share on other sites More sharing options...
rootKID Posted June 7, 2012 Author Share Posted June 7, 2012 nono... i did try with the one on... then i tried change back to undo the errors ... just change that with the one right under it ..., Link to comment Share on other sites More sharing options...
birbal Posted June 7, 2012 Share Posted June 7, 2012 you need to change that i had explained why it should not working. if after changing that part is showing error that means probably in other part of you code is not functioning as it should be. we need to see those errors Link to comment Share on other sites More sharing options...
rootKID Posted June 7, 2012 Author Share Posted June 7, 2012 (edited) i uploaded a image with the errors... ... but anyways... here are the code now as i added it before the code i sended... shop.php: <?phpecho "<pre>";print_r($_SESSION);echo "</pre>"; include ("shop_categories.php"); echo "<br />";var_dump($_GET);$catID = $_GET['cat_id'];//if($_GET['cat_id'] == "")if(isset($_GET['cat_id'])){ $query = "SELECT * FROM shop_items"; $result = mysql_query($query)or die(mysql_error());}else { $query = "SELECT * FROM shop_items WHERE FK_catID = $catID"; $result = mysql_query($query)or die(mysql_error());} /*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/if(!$catID == ""){echo "Succes! [CAT_ID ECHO]";}else {echo "Noob! [CAT_ID ECHO]";}/*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/ echo $catID; if(mysql_num_rows($result)>0)//Checking to see if there is any rows to take...{echo "<form action='' method='post'>";echo "<table class='shop_table_100'>";echo "<tr class='shop_tr_holder_css'>";echo "<td>Add</td>";echo "<td>Amount</td>";echo "<td>Product Name</td>";echo "<td>Price</td>";echo "<td>More Info</td>";echo "</tr>";while ($row = mysql_fetch_assoc($result)){echo "<tr>\n";echo "<td><input type='checkbox' name='check_addbox[".$row['item_id']."]' /></td>\n"; ////extra array...echo "<td><input type='text' name='amount[".$row['item_id']."]' size='1' value='1' /></td>\n"; //With extra array...echo "<td>".$row['item_name']."</td>\n";echo "<td>".$row['item_price']." USD</td>\n";echo "<td><a href='shop_details.php?item_id=".$row['item_id']."'>Info</a></td>\n";echo "</tr>\n";}echo "</table>";echo "</form>"; echo "<form action='' method='post'>";echo "<table class='shop_table_100'";echo "<tr>";echo "<td><input type='submit' name='add_item' id='submit' class='shop_add_submit_button' value='Update Cart' /></td>";echo "</tr>";echo "</table>";echo "</form>"; }//Ending IF (Num_Rows...)else{echo "<form action='' method='post'>";echo "<table class='shop_table_100'>"; echo "<tr class='shop_tr_holder_css'>";echo "<td>ERROR!</td>";echo "</tr>"; echo "</table>";echo "</form>"; echo "<form action='' method='post'>";echo "<table class='shop_table_100'>"; echo "<tr>";echo "<td>There are no Products to show yet.</td>";echo "</tr>"; echo "</table>";echo "</form>";} if(isset($_POST['add_item'])){if(!empty($_POST['check_addbox'])){ foreach($_POST['check_addbox'] as $p_id => $check) { $amount = $_POST['amount'][$p_id]; //Getting the Amount from the box... [p_id] is indicating what product it is (the checkbox...) $_SESSION['cart'][$p_id] += $amount; //adding them to the session... header("location: shop.php"); }}}?> category file: <?php$under_query = "SELECT * FROM shop_cat";$under_result = mysql_query($under_query)or die(mysql_error()); if(mysql_num_rows($under_result)>0)//Checking to see if there is any rows to take...{while($u_row = mysql_fetch_assoc($under_result)){echo "<a href='shop.php?cat_id=".$u_row['shop_cat_id']."'>".$u_row['shop_cat_name']."</a> ";}}//If ends...else {echo "No categories to show yet.";}/*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/if($under_query == ""){echo "Succes! [CAT_ID ECHO]";}else {echo "Noob! [CAT_ID ECHO]";}/*ECHO THE CAT_ID FOR SEEING IF ANYTHING COMES OUT...*/?> Error: Notice: Undefined index: cat_id in C:\xampp\htdocs\shop\shop.php on line 80You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Hope it helps ...tell me if ya needing more... note that if your telling me there is a error somewhere else, then i dont know what to do since i dont have that much more to add...in anyways, then i can see somfthing is wrong with the SQL as it says up in the error field, and it did not tell me that part last time, so i suppose i did not look that part since it looked very much the same to me on the screen first time i looked... sorry for that part :/... in anyway... i suppose its the SQL that needs a little hand then?... . Edited June 7, 2012 by rootKID Link to comment Share on other sites More sharing options...
thescientist Posted June 7, 2012 Share Posted June 7, 2012 (edited) I'm pretty sure we've gone over this before, but's let do it one more time.... $catID = $_GET['cat_id']; //don't do this. that's why you use isset. you will always get an error here if cat_id is not in $_GET//if($_GET['cat_id'] == "")//why aren't you using cat_id if it's provided? this all looks backwards. you should use cat_id if it's set, else you shouldn'tif(isset($_GET['cat_id'])){ $query = "SELECT * FROM shop_items"; $result = mysql_query($query)or die(mysql_error());}else { $query = "SELECT * FROM shop_items WHERE FK_catID = $catID"; $result = mysql_query($query)or die(mysql_error());} so to break it down again, you almost had it here if(isset($_GET['cat_id'])){ $query = "SELECT * FROM shop_items"; $result = mysql_query($query)or die(mysql_error());}else { $query = "SELECT * FROM shop_items WHERE FK_catID = $catID"; $result = mysql_query($query)or die(mysql_error());} but you're still doing it backwards. I'm pretty sure this what I've suggested to you in the past if(isset($_GET['cat_id'])){ $query = "SELECT * FROM shop_items WHERE FK_catID = " . $_GET['cat_id'];}else { $query = "SELECT * FROM shop_items";}$result = mysql_query($query)or die(mysql_error()); Edited June 7, 2012 by thescientist Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now