473,544 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
+ 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 1736
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("conn info.php")?>
<?session_start ();?>
<html>
<head>
<title>Products </title>
</head>
<link rel="stylesheet " type="text/css" href="style.css "/>
<body background="htt p://i145.photobucke t.com/albums/r224/lucy_lew/backgroundandlo go.jpg" border="0" alt="background img">
<h1>
<a href="login.php ">Home</a>&nbsp;&nbsp;
<a href="search.ph p">Search</a>&nbsp;&nbsp;
<a href="products. php">Products</a>&nbsp;&nbsp;
<a href="basket.ph p">Shopping Basket</a>&nbsp;&nbsp;
<a href="register. php">Register New User</a>
</h1>

</div>
<div id="container" >
<div id="left_conten t">
<div id = "left_text" >
<?
$query="select * FROM products ";
$result=mysql_q uery($query) or die("Couldnt do it");?>
<?$numrows=mysq l_num_rows($res ult);
if ($numrows>0)
{?>
<table border="1">
<?
while($r=mysql_ fetch_array($re sult))
{?>
<form action="basket. php" method="post">
<td><?echo $r["productid"];?></td>
<td><?echo $r["price"];?></td>
<td><?echo $r["productnam e"];?></td>
<td><img src="images/<?echo $r["productima ge"];?>" alt="Image"></td>
<input type="hidden" name="productid " <?echo $r['productid'];?>>
<input type="hidden" name="price" <?echo $r['price'];?>>
<input type="hidden" name="productna me" <?echo $r['productname'];?>>
<td><input type="submit" value="Add to Basket">
<td/>
</form>

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

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

<?
$productid=$_PO ST["productid"];
$price=$_POST["price"];
$productname=$_ POST["productnam e"];

$query = mysql_query("IN SERT INTO basket(producti d,price,product name)
VALUES('$produc tid','$price',' $productname')" )or die("Couldn't") ;

?>
Go to Basket:
<a href="showbaske t.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\wwwr oot\lucyclewis\ basket.php on line 23

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

Notice: Undefined index: productname in d:\inetpub\wwwr oot\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

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

Similar topics

7
2802
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: Undefined variable PHP Notice: Undefined index PHP Notice: Undefined property I'd like to go back and fix what I can, but I'm wondering: how good...
9
9593
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 is not a fluke. It seems like most programming languages would crash if you used an undefined index. Why does PHP work the way it does? My...
4
7173
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: Undefined index: city in /home/www/reformcagunlaws.com/new.php on line 8 PHP Notice: Undefined index: county in...
9
1859
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 behavior but would like another set of eyes to check. #include <math.h> #include <stdlib.h> extern float window;
7
2197
by: deepak | last post by:
Using 'char' as an array index is an undefined behavior?
3
4956
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 index: abdatum in /zipcode.php on line 13 Notice: Undefined index: zimmer in /zipcode.php on line 14 Notice: Undefined index: city in /zipcode.php...
3
5484
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: Undefined index: FriendName in D:\Yan\Over_8\SendEmail.php on line 4, Notice: Undefined index: FriendEmail in D:\Yan\Over_8\SendEmail.php on line 5,...
15
4452
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 enased whitespace (to my best memory) AT other times I get an undefined index notice as below: Notice: Undefined index: last_reminder_id in...
5
7170
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 local server it was working fine but giving some errors those are Notice: Undefined index: phplogin in C:\Inetpub\wwwroot\sampleft\index.php on line...
3
3856
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 (empty($info)) { $info='noinfo'; } changeinfo($info); Hey everyone, I keep getting an error regarding the above code. These are the errors: ...
0
7359
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7360
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5895
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5288
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3400
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3398
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1833
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 we have to send another system
1
982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
651
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.