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 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.
[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>
<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>
<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>
<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 = 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]
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\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...
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.
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
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!
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: ...
|
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...
|
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: ...
|
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...
|
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...
|
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:...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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 ...
| |