473,466 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

undefined index

6 New Member
ive got a box i want to click which will add the product to the basket but i keep gettin the undefined index error

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?include("conninfo.php")?>
  3. <?session_start();?>
  4. <html>
  5. <head>
  6. <title>Products</title>
  7. </head>
  8. <link rel="stylesheet" type="text/css" href="style.css"/>
  9. <body background="http://i145.photobucket.com/albums/r224/lucy_lew/backgroundandlogo.jpg" border="0" alt="backgroundimg">
  10. <h1>
  11.     <a href="login.php">Home</a>&nbsp;&nbsp;
  12.     <a href="search.php">Search</a>&nbsp;&nbsp;
  13.     <a href="products.php">Products</a>&nbsp;&nbsp;
  14.     <a href="basket.php">Shopping Basket</a>&nbsp;&nbsp;
  15.   <a href="register.php">Register New User</a>
  16. </h1>
  17.  
  18.     </div>
  19.     <div id="container">
  20.       <div id="left_content">
  21.         <div id = "left_text">
  22.         <?
  23.         $query="select * FROM products ";
  24.         $result=mysql_query($query) or die("Couldnt do it");?>
  25.         <?$numrows=mysql_num_rows($result);
  26.         if ($numrows>0)
  27.         {?>
  28.          <table border="1">
  29.              <?            
  30.          while($r=mysql_fetch_array($result))
  31.       {?>
  32.             <form action="basket.php" method="post">
  33.       <td><?echo $r["price"];?></td>
  34.             <td><?echo $r["productname"];?></td>
  35.             <td><img src="images/<?echo $r["productimage"];?>" alt="Image"></td>
  36.             <td><input type="submit" value="Add to Basket"><td/>
  37.       </form>
  38.  
  39.          </td>
  40.             </tr>
  41.             <?
  42.       }
  43.       ?>
  44.       </table>
  45.  
  46. <?}
  47. else
  48. {
  49. echo("Nothing Found.");
  50. }
  51.  
  52.  
  53.  
Expand|Select|Wrap|Line Numbers
  1. <?include("conninfo.php");?>
  2. <?session_start();?>
  3. <html>
  4. <link rel="stylesheet" type="text/css" href="style.css"/>
  5. <body background="http://i145.photobucket.com/albums/r224/lucy_lew/backgroundandlogo.jpg" border="0" alt="backgroundimg">
  6. <h1>
  7.     <a href="login.php">Home</a>&nbsp;&nbsp;
  8.     <a href="search.php">Search</a>&nbsp;&nbsp;
  9.     <a href="products.php">Products</a>&nbsp;&nbsp;
  10.     <a href="basket.php">Shopping Basket</a>&nbsp;&nbsp;
  11.   <a href="register.php">Register New User</a>
  12. </h1>
  13.  
  14. <?
  15. $productid=$_POST["productid"];
  16. $price=$_POST["price"];
  17. $productname=$_POST["productname"];
  18.  
  19. $query = "INSERT INTO basket(productid, price,productname)
  20. VALUES'$productid','$price','$productname'" or die("Couldn't");
  21. $result=mysql_query($query);
  22. ?>
  23. Go to Basket:
  24. <a href="showbasket.php">Go to Basket</a>
  25. </html>
  26.  
  27.  
  28.  
  29.  
  30.  
Sep 3 '07 #1
11 1731
ak1dnar
1,584 Recognized Expert Top Contributor
Welcome to theScripts.com

Could you please post the entire error message here, because It will help to find out the errors easily as it is saying well, where the problem occurred, rather than your post.
Sep 3 '07 #2
Lucylew
6 New Member
[PHP]
<?include("conninfo.php")?>
<?session_start();?>
<html>
<head>
<title>Products</title>
</head>
<link rel="stylesheet" type="text/css" href="style.css"/>
<body background="http://i145.photobucket.com/albums/r224/lucy_lew/backgroundandlogo.jpg" border="0" alt="backgroundimg">
<h1>
<a href="login.php">Home</a>&nbsp;&nbsp;
<a href="search.php">Search</a>&nbsp;&nbsp;
<a href="products.php">Products</a>&nbsp;&nbsp;
<a href="basket.php">Shopping Basket</a>&nbsp;&nbsp;
<a href="register.php">Register New User</a>
</h1>

</div>
<div id="container">
<div id="left_content">
<div id = "left_text">
<?
$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="basket.php" method="post">
<td><?echo $r["productid"];?></td>
<td><?echo $r["price"];?></td>
<td><?echo $r["productname"];?></td>
<td><img src="images/<?echo $r["productimage"];?>" alt="Image"></td>
<input type="hidden" name="productid" <?echo $r['productid'];?>>
<input type="hidden" name="price" <?echo $r['price'];?>>
<input type="hidden" name="productname" <?echo $r['productname'];?>>
<td><input type="submit" value="Add to Basket">
<td/>
</form>

</td>
</tr>
<?
}
?>
</table>

<?}
else
{
echo("Nothing Found.");
}
[/PHP]
[PHP]
<?include("conninfo.php");?>
<?session_start();?>
<html>
<link rel="stylesheet" type="text/css" href="style.css"/>
<body background="http://i145.photobucket.com/albums/r224/lucy_lew/backgroundandlogo.jpg" border="0" alt="backgroundimg">
<h1>
<a href="login.php">Home</a>&nbsp;&nbsp;
<a href="search.php">Search</a>&nbsp;&nbsp;
<a href="products.php">Products</a>&nbsp;&nbsp;
<a href="basket.php">Shopping Basket</a>&nbsp;&nbsp;
<a href="register.php">Register New User</a>
</h1>

<?
$productid=$_POST["productid"];
$price=$_POST["price"];
$productname=$_POST["productname"];

$query = mysql_query("INSERT INTO basket(productid,price,productname)
VALUES('$productid','$price','$productname')")or die("Couldn't");

?>
Go to Basket:
<a href="showbasket.php">Click here</a>
</html>
[/PHP]
Sep 3 '07 #3
ak1dnar
1,584 Recognized Expert Top Contributor
you should always initialize your variables before use, That is the meaning of your eror, Do you have any undefined variable.? Its there on the Line number of your Error report.
Sep 3 '07 #4
Lucylew
6 New Member
the error says that these lines are unfined:
Expand|Select|Wrap|Line Numbers
  1. $productid=$_POST["productid"];
  2. $price=$_POST["price"];
  3. $productname=$_POST["productname"];
  4.  
could u please tell me how to resolve this error coz ive tryed loads of things but just cant find wat it is
Sep 3 '07 #5
ak1dnar
1,584 Recognized Expert Top Contributor
Hi there,
when you sending the hidden form fields, there is no value with them.Try to send them too
This will work for you.

Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" name="productid" value="<?Php echo $r['productid'];?>"/>
  2. <input type="hidden" name="price" value="<?Php echo $r['price'];?>"/>
  3. <input type="hidden" name="productname" value="<?Php echo $r['productname'];?>"/>
  4.  
Post back with your updates. Thanks :)
Sep 4 '07 #6
Lucylew
6 New Member
Hi there,
when you sending the hidden form fields, there is no value with them.Try to send them too
This will work for you.

Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" name="productid" value="<?Php echo $r['productid'];?>"/>
  2. <input type="hidden" name="price" value="<?Php echo $r['price'];?>"/>
  3. <input type="hidden" name="productname" value="<?Php echo $r['productname'];?>"/>
  4.  
Post back with your updates. Thanks :)
Hi, thanks for that code i was just wondering where abouts to put it coz ive tryed it on the basket page and i still am gettin the "undefined index" error
Sep 4 '07 #7
ak1dnar
1,584 Recognized Expert Top Contributor
Hi, thanks for that code i was just wondering where abouts to put it coz ive tryed it on the basket page and i still am gettin the "undefined index" error
You have to put the hidden parameters to the form. That form is the one which calling for the php script to process the form data, additionally now you getting the error from the called script. as undefined index. So first put the values to the calling script.Then post it.
You should replace the line number 36,37,38 on this post.
Sep 4 '07 #8
Lucylew
6 New Member
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <?include("conninfo.php")?>
  4. <html>
  5. <head>
  6. <title>Products</title>
  7. </head>
  8. <link rel="stylesheet" type="text/css" href="style.css"/>
  9. <body background="http://i145.photobucket.com/albums/r224/lucy_lew/backgroundandlogo.jpg" border="0" alt="backgroundimg">
  10. <h1>
  11.     <a href="login.php">Home</a>&nbsp;&nbsp;
  12.     <a href="search.php">Search</a>&nbsp;&nbsp;
  13.     <a href="products.php">Products</a>&nbsp;&nbsp;
  14.     <a href="basket.php">Shopping Basket</a>&nbsp;&nbsp;
  15.   <a href="register.php">Register New User</a>
  16. </h1>
  17.  
  18.     </div>
  19.     <div id="container">
  20.       <div id="left_content">
  21.         <div id = "left_text">
  22.         <?
  23.         $query="select * FROM products ";
  24.         $result=mysql_query($query) or die("Couldnt do it");?>
  25.         <?$numrows=mysql_num_rows($result);
  26.         if ($numrows>0)
  27.         {?>
  28.          <table border="1">
  29.              <?            
  30.          while($r=mysql_fetch_array($result))
  31.       {?>
  32.             <form action="basket.php" method="post">
  33.  
  34.             <td><?echo $r["productid"];?></td>
  35.       <td><?echo $r["price"];?></td>
  36.             <td><?echo $r["productname"];?></td>
  37.             <td><img src="images/<?echo $r["productimage"];?>" alt="Image"></td>
  38.             <td><input type="submit" value="Add to Basket">
  39.             <td/>
  40.       </form>
  41.  
  42.          </td>
  43.             </tr>
  44.             <?
  45.       }
  46.       ?>
  47.       </table>
  48.  
  49. <?}
  50. else
  51. {
  52. echo("Nothing Found.");
  53. }
  54.  
  55.  
  56.  
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
  4.  
  5. <html>
  6. <link rel="stylesheet" type="text/css" href="style.css"/>
  7. <body background="http://i145.photobucket.com/albums/r224/lucy_lew/backgroundandlogo.jpg" border="0" alt="backgroundimg">
  8. <h1>
  9.     <a href="login.php">Home</a>&nbsp;&nbsp;
  10.     <a href="search.php">Search</a>&nbsp;&nbsp;
  11.     <a href="products.php">Products</a>&nbsp;&nbsp;
  12.     <a href="basket.php">Shopping Basket</a>&nbsp;&nbsp;
  13.   <a href="register.php">Register New User</a>&nbsp;&nbsp;
  14.  
  15. </h1>
  16. <head>
  17. <title>Basket</title>
  18. </head>
  19. <body>
  20.  
  21. </body>    
  22.  
  23. <?include("conninfo.php");
  24.  
  25.         $productid=$_POST["productid"];
  26.         $price=$_POST["price"];
  27.         $productname=$_POST["productname"];
  28.  
  29.                 $query = mysql_query("INSERT INTO basket(productid,price,productname) 
  30.         VALUES ('$productid','$price','$productname')")or die("Couldn't")
  31.  
  32. ?>
  33. Added to the basket
  34. </html>
  35.  
I think ive put that code in in the right place because its adding to the basket but its adding blank entries, this is the error i get on the basket page:

Notice: Undefined index: productid in d:\inetpub\wwwroot\lucyclewis\basket.php on line 23

Notice: Undefined index: price in d:\inetpub\wwwroot\lucyclewis\basket.php on line 24

Notice: Undefined index: productname in d:\inetpub\wwwroot\lucyclewis\basket.php on line 25
Added to the basket

Please help its really stressing me out...
Sep 4 '07 #9
ak1dnar
1,584 Recognized Expert Top Contributor
Where is the <hidden> fields? Still Its not there in the above post. you have to add them inside the FORM on the first code listening.


Please use the code tags in this format.
[code=php]
and
make sure to close them as described in the reply Guidelines on the right hand side with your text editor.
Sep 4 '07 #10
Lucylew
6 New Member
Where is the <hidden> fields? Still Its not there in the above post. you have to add them inside the FORM on the first code listening.


Please use the code tags in this format.
[code=php]
and
make sure to close them as described in the reply Guidelines on the right hand side with your text editor.
sorry, it all works now thank you so so so soooo much for your help
Sep 4 '07 #11
ak1dnar
1,584 Recognized Expert Top Contributor
sorry, it all works now thank you so so so soooo much for your help
No Problem, glad you got it working. Post back any time if you ever need anything. good luck!
Sep 4 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Coder Droid | last post by:
I decided to run some code with errors set to E_ALL, just to see what I would run across. It caught a few things, but 90% or better of the messages were of the 'undefined' kind: PHP Notice: ...
9
by: petermichaux | last post by:
Hi, I am curious about how php deals with the following situation where I use an undefined index into an array. PHP seems to be behaving exactly how I want it to but I want to make sure that it...
4
by: John Oliver | last post by:
PHP Notice: Undefined index: name in /home/www/reformcagunlaws.com/new.php on line 6 PHP Notice: Undefined index: address in /home/www/reformcagunlaws.com/new.php on line 7 PHP Notice: ...
9
by: Alan Schroeder | last post by:
The following code produces the expected results on a PC using gcc, but I need to port it (or least something similar) to a different platform/compiler. I don't think I've introduced any undefined...
7
by: deepak | last post by:
Using 'char' as an array index is an undefined behavior?
3
cassbiz
by: cassbiz | last post by:
Here are the errors that are coming up in my error_log Notice: Undefined index: andatum in /zipcode.php on line 11 Notice: Undefined index: andatum in /zipcode.php on line 12 Notice: Undefined...
3
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice:...
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
5
by: siyaverma | last post by:
Hi, I am new to php, i was doing some small chnages in a project developed by my collegue who left the job and i got the responsibility for that, After doing some changes when i run it on my...
3
by: sickboy | last post by:
$channels=$_GET; if (empty($channels)) { $channels='blank'; } changechannels($channels); $theatre=$_GET; if (empty($theatre)) { $theatre='splash'; } changetheatre($theatre); $info=$_GET; if...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.