puggo Posted September 3, 2007 Share Posted September 3, 2007 Hi ive got some code that i need helping with, basically i want to click on a box next to a product and then send it into the basket. Below is the products. <?include("conninfo.php")?> <?php session_start(); ?> <html> <head> <title>The Music Shop</title> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <div id="header"><h1><img src="Images/banner.jpg"</h1> </div> <div id = "top_nav"> <a href="index.html">Home</a><span class="invisible"> | </span> <a href="register.php">Register</a><span class="invisible"> | </span> <a href="account.php">Login</a><span class="invisible"> | </span> <a href="products.php">Products</a><span class="invisible"> | </span> <a href="search.php">Search</a><span class="invisible"> | </span> <a href="cart.php">Shopping Basket|</a> </div> <? $query="select * FROM products "; $result=mysql_query($query) or die("Couldnt do it");?> <?$numrows=mysql_num_rows($result); if ($numrows>0) {?> <table border="1"> <? while($r=mysql_fetch_array($result)) {?> <form action="cart.php" method="post"> <tr> <td><?echo $r['ProductID'];?></td> <td><?echo $r["ProductPrice"];?></td> <td><?echo $r["ProductName"];?></td> <td><img src="images/<?echo $r["Preview"];?>" alt="Image"></td> <td><input type="submit" value="Add to Basket"><td/> </form> </td> </tr> <? } ?> </table> <?} else { echo("Nothing Found."); } Which leads onto the cart.php <?include("conninfo.php")?> <?php session_start(); ?> <html> <head> <title>The Music Shop</title> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <div id="header"><h1><img src="Images/banner.jpg"</h1> </div> <div id = "top_nav"> <a href="index.html">Home</a><span class="invisible"> | </span> <a href="register.php">Register</a><span class="invisible"> | </span> <a href="account.php">Login</a><span class="invisible"> | </span> <a href="products.php">Products</a><span class="invisible"> | </span> <a href="search.php">Search</a><span class="invisible"> | </span> <a href="cart.php">Shopping Basket|</a> </div> <? $id=$_POST['ProductID']; $price=$_POST['ProductPrice']; $name=$_POST['ProductName']; $query = mysql_query("INSERT INTO basket(ProductID,ProductPrice,ProductName) VALUES('$id','$price','$name'")or die("Couldnt"); ?> Go to Basket: </body> </html> Whenever i click on a box to "buy" the product i get: Notice: Undefined index: ProductID in d:\inetpub\wwwroot\SimonJenkins\Assignment\cart.php on line 26 Notice: Undefined index: ProductPrice in d:\inetpub\wwwroot\SimonJenkins\Assignment\cart.php on line 27 Notice: Undefined index: ProductName in d:\inetpub\wwwroot\SimonJenkins\Assignment\cart.php on line 28 Couldnt Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted September 3, 2007 Share Posted September 3, 2007 you have not set any input to transfer the relevant data. try using <input type="hidden" name="x" id="x" value="<?php echo $val; ?>" /> for productid, price and name (set the values accordingly) Quote Link to comment Share on other sites More sharing options...
puggo Posted September 3, 2007 Author Share Posted September 3, 2007 thanks but if i set the input type to hidden how do i select the item. Would this be the correct code? <td><input type="hidden" name="ProductName" price="ProductPrice" id="ProductID" value="<?php echo $val; ?>"<td/> Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted September 3, 2007 Share Posted September 3, 2007 thanks but if i set the input type to hidden how do i select the item. Would this be the correct code? <td><input type="hidden" name="ProductName" price="ProductPrice" id="ProductID" value="<?php echo $val; ?>"<td/> Yes. Quote Link to comment Share on other sites More sharing options...
puggo Posted September 3, 2007 Author Share Posted September 3, 2007 I still get the undefined index error but now only 2 of them and not 3 Notice: Undefined index: ProductID in d:\inetpub\wwwroot\SimonJenkins\Assignment\cart.php on line 26 Notice: Undefined index: ProductPrice in d:\inetpub\wwwroot\SimonJenkins\Assignment\cart.php on line 27 Couldnt Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted September 3, 2007 Share Posted September 3, 2007 <input type="hidden" name="ProductID" id="ProductID" value="<?php echo $r['ProductID'];?>" /> <input type="hidden" name="ProductPrice" id="ProductPrice" value="<?php echo $r['ProductPrice'];?>" /> <input type="hidden" name="ProductName" id="ProductName" value="<?php echo $r['ProductName'];?>" /> If you want something done properly.... NOW you may/maynot notice the flaw in your method... You shoudl only need to pass the prodcutID - use a query on the processing script to grab the proce - otherwiose someone could hood wink the system and get something for free!!!! Quote Link to comment Share on other sites More sharing options...
puggo Posted September 3, 2007 Author Share Posted September 3, 2007 thanks agian toon, i did write in that code when i was trying to get it to work, now i dont get any undefined indexs but get a "couldnt" this is really annoying me, how do i get around it? Quote Link to comment Share on other sites More sharing options...
puggo Posted September 3, 2007 Author Share Posted September 3, 2007 Anyone? It's not adding to my database and i keep getting the "couldnt" message. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted September 3, 2007 Share Posted September 3, 2007 Try to use mysql_error() to find out what the MySQL error is. Quote Link to comment 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.