Page 1 of 1
undefined index help
Posted: Tue Feb 13, 2007 7:00 am
by keveh
I made a website for somebody and hosted it on my own server for testing, everything ran fine.
I then put it on their servers and I get the following error on pages where I am trying to get POST results:
Notice: Undefined index: extra1box in D:\Domains\lunarcaravans.com\wwwroot\newlunar\caravans\ariva\ariva_prices.php on line 6
Notice: Undefined index: extra3box in D:\Domains\lunarcaravans.com\wwwroot\newlunar\caravans\ariva\ariva_prices.php on line 14
Here is my code:
Code: Select all
if($_POST['extra1box'] == "on"){
$total = $total + $_POST['extra1'];
}
if(isset($_POST['alloy'])){
$total = $total + $_POST['alloy'];
}
if($_POST['extra3box'] == "on"){
$total = $total + $_POST['extra3'];
}
I was wondering what would cause this?
Also, I don't get that error for the alloy in that section of the code, but I do when it is called here:
Code: Select all
<input type="radio" name="alloy" value="260" <?php if($_POST['alloy'] == "260"){echo('checked="checked" ');}?>/>(2)<br />
<input type="radio" name="alloy" value="520" <?php if($_POST['alloy'] == "520"){echo('checked="checked" ');}?>/>(4)
Here is the error:
Notice: Undefined index: alloy in D:\Domains\lunarcaravans.com\wwwroot\newlunar\caravans\ariva\ariva_prices.php on line 48
Posted: Tue Feb 13, 2007 7:40 am
by ryuuka
Code: Select all
if($_POST['extra1box'] == "on"){
$total = $total + $_POST['extra1'];
}
if(isset($_POST['alloy'])){
$total = $total + $_POST['alloy'];
}
if($_POST['extra3box'] == "on"){
$total = $total + $_POST['extra3'];
}
this means you dont have any information posted to these indexes
and thus they are unidentified.
can you give us the source code to the page with the form please?
Posted: Tue Feb 13, 2007 7:43 am
by blackbeard
turn off the notice error reporting on the client machine.
Posted: Tue Feb 13, 2007 7:46 am
by keveh
ryuuka wrote:can you give us the source code to the page with the form please?
Code: Select all
<?php
$total = 11295;
if($_POST['extra1box'] == "on"){
$total = $total + $_POST['extra1'];
}
if(isset($_POST['alloy'])){
$total = $total + $_POST['alloy'];
}
if($_POST['extra3box'] == "on"){
$total = $total + $_POST['extra3'];
}
?>
<form method="post" action="caravan_ariva.php">
<input type="hidden" name="ariva" value="ariva" />
<input type="hidden" name="page" value="price" />
<table width="400" border="0" align="center">
<tr height="5"></tr>
<tr>
<td colspan="3" style="font-size:16px;font-weight:bold;">Price <font style="font-size:10px;">(RRP inc VAT)</font> - £11,295</td>
</tr>
<tr height="5"></tr>
<tr>
<td width="250"><b>Extras</b></td>
<td width="100"><b>Price</b></td>
<td width="50"><b>Include</b></td>
</tr>
<tr height="5"></tr>
<tr>
<td width="250">Spare Wheel (steel)</td>
<td width="100">£112</td>
<td width="50">
<input type="checkbox" name="extra1box" <?php if($_POST['extra1box'] == "on"){echo('checked="checked"');}?> />
<input type="hidden" name="extra1" value="112" />
</td>
</tr>
<tr height="5"></tr>
<tr>
<td width="250">Alloy Wheels (includes bolts)</td>
<td width="100">£130<br />(per wheel)</td>
<td width="50">
<input type="radio" name="alloy" value="260" <?php if($_POST['alloy'] == "260"){echo('checked="checked" ');}?>/>(2)<br />
<input type="radio" name="alloy" value="520" <?php if($_POST['alloy'] == "520"){echo('checked="checked" ');}?>/>(4)
</td>
</tr>
<tr height="5"></tr>
<tr>
<td width="250">
Fabric Change<br />
<font style="font-size:10px;">From standard bedding curtain and carpet.<br />Materials (not including fixed bedroom- construction style remains the same as in the model range).</font>
</td>
<td width="100">£220<br /></td>
<td width="50">
<input type="checkbox" name="extra4box" <?php if($_POST['extra4box'] == "on"){echo('checked="checked"');}?> />
<input type="hidden" name="extra4" value="220" />
</td>
</tr>
<tr height="5"></tr>
<td colspan="3" align="right"><input type="submit" value="Calculate Price" class="loginButton" /></td>
</tr>
<tr height="5"></tr>
<tr>
<td style="background:#E8E8E8;font-size:16px;font-weight:bold;padding:5px;">Total Price</td>
<td colspan="2"style="background:#CACACA;font-size:16px;font-weight:bold;padding:5px;">
£<?php echo(number_format($total)); ?>
</td>
</tr>
<tr height="5"></tr>
<tr>
<td colspan="2">For more information on additional extras contact your <a href="dealer.php">Nearest Dealer</a></td>
</tr>
</table>
</form>
Posted: Tue Feb 13, 2007 7:47 am
by Chris Corbyn
blackbeard wrote:turn off the notice error reporting on the client machine.
Don't ever do that. Use isset() or !empty() to check if the var exists. Fix your code, don't cover up the problems.
Code: Select all
if(isset($_POST['extra1box']) && $_POST['extra1box'] == "on"){
$total = $total + $_POST['extra1'];
}
if(isset($_POST['alloy'])){
$total = $total + $_POST['alloy'];
}
if(isset($_POST['extra3box']) && $_POST['extra3box'] == "on"){
$total = $total + $_POST['extra3'];
}
Posted: Tue Feb 13, 2007 8:10 am
by ryuuka
Code: Select all
<input type="checkbox" name="extra1box" <?php if($_POST['extra1box'] == "on"){echo('checked="checked"')};?>value="112" />
<input type="checkbox" name="extra4box" <?php if($_POST['extra4box'] == "on"){echo('checked="checked"')};?> value="220" />
input it this way
and loose the hidden types
extra3box doesnt exist
Posted: Tue Feb 13, 2007 8:11 am
by keveh
Thanks a lot d11wtq, that worked a treat
