Current location: Hot Scripts Forums » Programming Languages » PHP » Getting values from textboxes-Undefined index


Getting values from textboxes-Undefined index

Reply
  #1 (permalink)  
Old 12-14-09, 05:10 AM
Jimmy90 Jimmy90 is offline
New Member
 
Join Date: Dec 2009
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Getting values from textboxes-Undefined index

Hey guys, newbie here.

Having a slight problem trying to get values from textboxes. I am trying to retrieve data from a textbox in a html file, and if the value entered >= 1, then echo a small message. At the moment I am getting the error:

Notice: Undefined index: txtProduct0 in D:\wwwdata\DSA\2009-2010\dv003319\selection.php on line 35

For all my textboxes! Do not understand why!
Here is my php code:

Code:
<?php

$sProduct0 = $_POST['txtProduct0'];
$sProduct1 = $_POST['txtProduct1'];
$sProduct2 = $_POST['txtProduct2'];
$sProduct3 = $_POST['txtProduct3'];
$sProduct4 = $_POST['txtProduct4'];
$sProduct5 = $_POST['txtProduct5'];
$sProduct6 = $_POST['txtProduct6'];
$sProduct7 = $_POST['txtProduct7'];
$sProduct8 = $_POST['txtProduct8'];
$sProduct9 = $_POST['txtProduct9'];

if ($sProduct0 >= 1)
{
echo ('You have added $sProduct0 Lifeflow LF09 Blood Pressure Monitors to your basket.');
}

if ($sProduct1 >= 1)
{
echo ('You have added $sProduct1 Lifeflow Auto Blood Pressure Monitors to your basket.');
}

if ($sProduct2 >= 1)
{
echo ('You have added $sProduct2 Tryton Cardiology Stethoscopes to your basket.');
}

if ($sProduct3 >= 1)
{
echo ('You have added $sProduct3 Unit Dosage Drug Trolleys to your basket.');
}

if ($sProduct4 >= 1)
{
echo ('You have added $sProduct4 Dressing Scissors to your basket.');
}

if ($sProduct5 >= 1)
{
echo ('You have added $sProduct5 Operating Scissors to your basket.');
}

if ($sProduct6 >= 1)
{
echo ('You have added $sProduct6 Disposable Masks to your basket.');
}

if ($sProduct7 >= 1)
{
echo ('You have added $sProduct7 Latex Gloves (Large) to your basket.');
}

if ($sProduct8 >= 1)
{
echo ('You have added $sProduct8 Latex Gloves (Medium) to your basket.');
}

if ($sProduct9 >= 1)
{
echo ('You have added $sProduct9 Washproof Plasters to your basket.');
}

?>
Any help would be appreciated! Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-14-09, 08:50 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Please post the HTML.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-14-09, 09:11 AM
Jimmy90 Jimmy90 is offline
New Member
 
Join Date: Dec 2009
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
PHP file = selection.php

HTML (named selection.htm):

Code:
<body text="#006633">

<table width="427" height="619" border="1">
  <tr>
    <td><strong>Products</strong></td>
    <td><strong>Quantity</strong></td>
  </tr>
  <tr>
    <td>Lifeflow LF09 Blood Pressure Monitor</td>
    <td><input name="txtProduct0" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Lifeflow Auto Blood Pressure Monitor</td>
    <td><input name="txtProduct1" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Tryton Cardiology Stethoscope</td>
    <td><input name="txtProduct2" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Unit Dosage Drug Trolley</td>
    <td><input name="txtProduct3" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Dressing Scissors</td>
    <td><input name="txtProduct4" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Operating Scissors</td>
    <td><input name="txtProduct5" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Disposable Mask</td>
    <td><input name="txtProduct6" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Latex Gloves (Large)</td>
    <td><input name="txtProduct7" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Latex Gloves (Medium)</td>
    <td><input name="txtProduct8" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Washproof Plasters</td>
    <td><input name="txtProduct9" type="text" value="0"></td>
  </tr>
</table>

<br>
<br>
<br>
<br>

<form action="http://fcetdev1.student.staffs.ac.uk/wwwdata/dsa/2009-2010/dv003319/selection.php" method="post"/>
<input type="submit" value="Choose your items">

</body>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 12-14-09, 10:56 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Move the form tag up above the table tag, so that it includes all the inputs.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
Jimmy90 (12-15-09)
  #5 (permalink)  
Old 12-15-09, 08:54 AM
therocket954's Avatar
therocket954 therocket954 is offline
Community Liaison
 
Join Date: Jul 2007
Location: Michigan, USA
Posts: 334
Thanks: 2
Thanked 8 Times in 8 Posts
Also, don't self-close the form tag itself. (Remove the slash from the end of the <form> tag). You'll need a form close tag below all of your form elements. This should work (replacing your HTML code with this):

HTML Code:
<body text="#006633">
<form action="http://fcetdev1.student.staffs.ac.uk/wwwdata/dsa/2009-2010/dv003319/selection.php" method="post">
<table width="427" height="619" border="1">
  <tr>
    <td><strong>Products</strong></td>
    <td><strong>Quantity</strong></td>
  </tr>
  <tr>
    <td>Lifeflow LF09 Blood Pressure Monitor</td>
    <td><input name="txtProduct0" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Lifeflow Auto Blood Pressure Monitor</td>
    <td><input name="txtProduct1" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Tryton Cardiology Stethoscope</td>
    <td><input name="txtProduct2" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Unit Dosage Drug Trolley</td>
    <td><input name="txtProduct3" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Dressing Scissors</td>
    <td><input name="txtProduct4" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Operating Scissors</td>
    <td><input name="txtProduct5" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Disposable Mask</td>
    <td><input name="txtProduct6" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Latex Gloves (Large)</td>
    <td><input name="txtProduct7" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Latex Gloves (Medium)</td>
    <td><input name="txtProduct8" type="text" value="0"></td>
  </tr>
  <tr>
    <td>Washproof Plasters</td>
    <td><input name="txtProduct9" type="text" value="0"></td>
  </tr>
</table>

<br>
<br>
<br>
<br>

<input type="submit" value="Choose your items">
</form>
</body>
__________________
--Eric Allison
Twitter: http://www.twitter.com/Eric_Allison
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to therocket954 For This Useful Post:
Jimmy90 (12-15-09)
  #6 (permalink)  
Old 12-15-09, 04:49 PM
Jimmy90 Jimmy90 is offline
New Member
 
Join Date: Dec 2009
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Sorry about the late reply:

Thanks for your help wirehopper, really appreiciate it. I have tested it and works great. Seems I was looking in the wrong place for an error heh.

Thanks for the reply too therocket954, seems like much better practice doing it that way, so I will change this also.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Auto Dealer Script nuzzle PHP 17 04-14-10 09:34 PM
ERROR - Notice: Undefined index: - ERROR tommyc325 PHP 5 11-11-08 07:40 PM
[SOLVED] No page no error? Hamed PHP 11 07-19-08 01:39 AM
No error message... stormshadow PHP 3 12-11-06 07:31 PM
Problems getting PHP-Nuke setup correctly TravisT PHP 2 12-17-05 08:54 PM


All times are GMT -5. The time now is 07:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.