ive got a box i want to click which will add the product to the basket but i keep gettin the undefined index error -
-
<?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>
-
<a href="search.php">Search</a>
-
<a href="products.php">Products</a>
-
<a href="basket.php">Shopping Basket</a>
-
<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["price"];?></td>
-
<td><?echo $r["productname"];?></td>
-
<td><img src="images/<?echo $r["productimage"];?>" alt="Image"></td>
-
<td><input type="submit" value="Add to Basket"><td/>
-
</form>
-
-
</td>
-
</tr>
-
<?
-
}
-
?>
-
</table>
-
-
<?}
-
else
-
{
-
echo("Nothing Found.");
-
}
-
-
-
-
<?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>
-
<a href="search.php">Search</a>
-
<a href="products.php">Products</a>
-
<a href="basket.php">Shopping Basket</a>
-
<a href="register.php">Register New User</a>
-
</h1>
-
-
<?
-
$productid=$_POST["productid"];
-
$price=$_POST["price"];
-
$productname=$_POST["productname"];
-
-
$query = "INSERT INTO basket(productid, price,productname)
-
VALUES'$productid','$price','$productname'" or die("Couldn't");
-
$result=mysql_query($query);
-
?>
-
Go to Basket:
-
<a href="showbasket.php">Go to Basket</a>
-
</html>
-
-
-
-
-
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.
[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>
<a href="search.ph p">Search</a>
<a href="products. php">Products</a>
<a href="basket.ph p">Shopping Basket</a>
<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>
<a href="search.ph p">Search</a>
<a href="products. php">Products</a>
<a href="basket.ph p">Shopping Basket</a>
<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]
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.
the error says that these lines are unfined: -
$productid=$_POST["productid"];
-
$price=$_POST["price"];
-
$productname=$_POST["productname"];
-
could u please tell me how to resolve this error coz ive tryed loads of things but just cant find wat it is
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. -
<input type="hidden" name="productid" value="<?Php echo $r['productid'];?>"/>
-
<input type="hidden" name="price" value="<?Php echo $r['price'];?>"/>
-
<input type="hidden" name="productname" value="<?Php echo $r['productname'];?>"/>
-
Post back with your updates. Thanks :)
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. -
<input type="hidden" name="productid" value="<?Php echo $r['productid'];?>"/>
-
<input type="hidden" name="price" value="<?Php echo $r['price'];?>"/>
-
<input type="hidden" name="productname" value="<?Php echo $r['productname'];?>"/>
-
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
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. -
-
-
<?include("conninfo.php")?>
-
<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>
-
<a href="search.php">Search</a>
-
<a href="products.php">Products</a>
-
<a href="basket.php">Shopping Basket</a>
-
<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>
-
<td><input type="submit" value="Add to Basket">
-
<td/>
-
</form>
-
-
</td>
-
</tr>
-
<?
-
}
-
?>
-
</table>
-
-
<?}
-
else
-
{
-
echo("Nothing Found.");
-
}
-
-
-
-
-
-
-
-
<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>
-
<a href="search.php">Search</a>
-
<a href="products.php">Products</a>
-
<a href="basket.php">Shopping Basket</a>
-
<a href="register.php">Register New User</a>
-
-
</h1>
-
<head>
-
<title>Basket</title>
-
</head>
-
<body>
-
-
</body>
-
-
<?include("conninfo.php");
-
-
$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")
-
-
?>
-
Added to the basket
-
</html>
-
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...
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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;
|
by: deepak |
last post by:
Using 'char' as an array index is an undefined behavior?
| |
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...
|
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,...
|
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...
|
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...
|
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:
...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |