arrays - PHP Shopping Cart Variable and Object errors -


i need eliminate errors im getting. have shopping cart displayed on products page way of cart update page. below pair of errors (notices) every product listed:

notice: undefined variable: obj in c:\xampp\htdocs\project2\browseproducts.php on line 89  notice: trying property of non-object in c:\xampp\htdocs\project2\browseproducts.php on line 89 

when click on of add cart buttons, nothing added cart , get:

notice: undefined index: stock in c:\xampp\htdocs\project2\cart_update.php on line 25 

my code is:

  <?php             $user = "root";             $password = "";             $database = "webstore";             mysql_connect("localhost", $user, $password);             @mysql_select_db($database) or die("unable select database");             $current_url = base64_encode("http://".$_server['http_host'].$_server['request_uri']);             $query = "select * products order category";             $result = mysql_query($query);              if($result === false) {             die(mysql_error());} // todo: better error handling                  // keeps getting next row until there no more              while ($row = mysql_fetch_array($result)) {                 echo "<tr>";                 echo "<form method='post' action='cart_update.php'>";                 echo "<td>" . "<img src=" .$row['iconurl'] . "alt=" .$row['name'] ."/>" . "</td>";                 echo "<td>" . $row['name'] . "</td>";                 echo "<td>" . $row['descr'] . "</td>";                 echo "<td>" . '$' . $row['price'] . "</td>";                 echo "<td>" . $row['stock'] . "</td>";                 echo "<td> <button class='add_to_cart'>add cart</button> </td>";         echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />';         echo '<input type="hidden" name="type" value="add" />';         echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';                  echo "</form>";                 echo "</tr>\n";             }              mysql_close();             ?>         </table> 

some of cart update code:

//add item in shopping cart if(isset($_post["type"]) && $_post["type"]=='add') {     $product_code   = filter_var($_post["product_code"], filter_sanitize_string); //product code     $stock    = filter_var($_post["stock"], filter_sanitize_number_int); //product code     $return_url     = \base64_decode($_post["return_url"]); //return url      //limit quantity single product     if($stock < 1){         die('<div align="center">we out of stock<br /><a href="browseproducts.php/">back products</a>.</div>');     }     $queryy = "select top 1 name,price products product_code='$product_code'";     //mysqli query - details of item db using product code     $results = mssql_query($queryy);     $obj = mssql_fetch_object($results); 

aaaany appreciated!


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -