Jump to content

Undefined index


puggo

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<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!!!!

Link to comment
Share on other sites

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.