Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undefined Index ..possible session error?

Status
Not open for further replies.

luds

Programmer
Jul 15, 2003
162
0
0
GB
Hi,

I've got 3 functions on 3 consecutive pages. Each function passes info onto the following page and asks more questions.

Question:
1. The variable $discountSelect only registers 1 on the next page... not the value that is assigned to it in the mysql table. They are all correct on page one, but on page 2 the companies are correct but the discount isn't.

2. going from page 2 to 3 I get an "Undefined Index" error for both $companySelect and $discountSelect. I think that this is a session error, the variables have ceased to exist, but I;m not sure.

Please can someone point me in the right direction, as after 3 days it's starting to get to me a little bit!

here are the functions:
function investment_list()
{

//list companies and % discount from db=client table company_list

$user="luds";
$host="localhost";
$password="";
$database="client";
$connection = mysql_connect($host,$user,$password) or die
("Couldn't connect to server!");
$db = mysql_select_db($database,$connection) or die ("Couldn't select database");
$query = "SELECT * FROM company_list ORDER BY companyName";
$result = mysql_query($query) or die ("couldn't execute.");

?>

<table width=&quot;350&quot;>
<th width=&quot;70%&quot; align=&quot;center&quot;>Company Name</th>
<th width=&quot;30%&quot; align=&quot;center&quot;>Percentage Discount</th>
</table>
<form action='companyP2.php' method='POST'>
<?php

while ($row = mysql_fetch_array($result))
{
extract($row);
?>
<table width=&quot;350&quot; bgcolor=&quot;#999999&quot;>

<tr>
<td width=&quot;70%&quot;>
<?php

echo &quot;<input type='radio' name='companySelect' value='$companyName'>$companyName\n&quot;; ?></td>

<td>
<?php echo &quot;<input name='discountSelect' value='$discount'\n<br>&quot;; ?></td>
</tr>
</table>


<?php
}
?>
<table>
<tr><td><input type=&quot;submit&quot; value=&quot;Move to Step Two&quot;></td></tr></table>
&quot;</form>&quot;;
<?php
}
?>




<?php
function investment_amount()
{

?>
<table bgcolor=&quot;#ffffff&quot;>
<form method='post' action=&quot;companyP3.php&quot;>
<table bgcolor=#cccccc>
<tr>
<td align=&quot;center&quot; colspan=&quot;2&quot;>
You have chosen the company &nbsp;<strong><?php echo $_POST['companySelect']; ?></strong>
</td></tr>

<tr>
<td align=&quot;center&quot; colspan=&quot;2&quot;>
which has a discount at the moment of <strong><?php echo $_POST['discountSelect']; ?></strong> &nbsp;percent
</td></tr>

<tr><td colspan=&quot;2&quot;>
Amount you wish to invest =&nbsp;£&nbsp;<input type=text name=sum_invested>
</td>
</tr>

<tr>
<td><input type=&quot;submit&quot; value=&quot;Next Step&quot;></td></tr>
</table>
<?php
}
?>



<?php
function display_registration_form2()
{


?>

<form method='post' action=&quot;register_new.php&quot;>
<table bgcolor=#cccccc>
<tr>
<td align=&quot;center&quot; colspan=&quot;2&quot;>You have chosen to invest <strong>£<?php echo $_POST['sum_invested']; ?></strong>&nbsp;
in&nbsp;<strong><?php echo $_POST['companySelect']; ?></strong></td></tr>
<tr>
<td align=&quot;center&quot; colspan=&quot;2&quot;>which has a discount at the moment of &nbsp;<strong>
<?php echo $_POST['discountSelect']; ?></strong> &nbsp;percent</td></tr>

<tr>
<td align=&quot;center&quot;>Please enter your personal details to submit this information</td></tr>
<tr>
<td>Email address:</td>
<td><input type=text name=email size=30 maxlength=100></td></tr>
<tr>
<td>Preferred username <br />(max 16 chars):</td>
<td valign=top><input type=text name=userName
size=16 maxlength=16></td></tr>
<tr>
<td>Password <br />(between 6 and 16 chars):</td>
<td valign=top><input type=password name=passwd
size=16 maxlength=16></td></tr>
<tr>
<td>Confirm password:</td>
<td><input type=password name=passwd2 size=16 maxlength=16></td></tr>
<tr>
<td>First Name:</td>
<td><input type=text name=firstName size=30 maxlength=100></td></tr>
<tr>
<td>Surname:</td>
<td valign=top><input type=text name=lastName size=16 maxlength=16></td></tr>
<tr>
<td>Address:</td>
<td valign=top><input type=text name=address size=16 maxlength=16></td></tr>


<td colspan=2 align=center>

<input type=submit value=&quot;Submit&quot;></td></tr>
</table></form>
<?php
}
?>


Cheers

luds

 
You can use

Code:
echo '<pre>';
print_r($_SESSION);

To display what session vars are available. I'd recommend displaying all the vars you are using at the top of each page to see what's going on. When you've got a clear idea of exactly what vars are doing what, you'll understand your code a great deal more.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top