...

View Full Version : If{} else{} statement help!!



lansing
06-14-2006, 11:23 PM
I have the code below & keep getting this error:
Parse error: parse error, unexpected T_ELSE in
/home/httpd/vhosts/domain.com/httpdocs/members/edit_account.php on line 85

I have looked at the code & don't see anything wrong. I have made sure that all my if {} else {} statements are closed & they are. Basically this page is a update page for user info. It displays the form that is refilled with their current info. Then when they click the Save button it queries customer_table the db for all their current info & inserts that into history_table, then it updates customer_table with their new info.

Then queries do have more data in them, but I deleted them before posting this code here.
<?php
if(isset($_POST['save']))
{
$id = $_SESSION['id'];
$history_details = mysql_query("SELECT * FROM $customer_table WHERE customers= '$id'");
while ($line = mysql_fetch_array($history_details)) {
$customers = stripslashes($line["customers"]);
echo'';

$sql = mysql_query("INSERT INTO $history_table (customers)
VALUES($customers)")
or die (mysql_error());

if(!$sql)
{
die('There has been an error updating your account. Please contact the webmaster.');
}
else
{
$id = $_SESSION['id'];
$customers_street = addslashes($_POST['customers_street']);

$update_customer = ("UPDATE $customer_table SET customers_street = '$customers_street'
WHERE customers = '$id'");
$update_query = mysql_query($update_customer) or die(mysql_error());

if(!$update_query)
{
echo 'Error in updating customer contact information!';
echo 'Try again or contact support';
}
else
{
echo 'Customer contact information successfully updated!';
}
}
}
else
{
$id = $_SESSION['id'];
$customer_details = mysql_query("SELECT * FROM $customer_table WHERE customers_id= '$id' ");
while ($line = mysql_fetch_array($customer_details)) {
$customers = stripslashes($line["customers"]);
echo'';
}
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" name="customer_details" id="customer_details">
<table width="100%" border="0" align="center" class="newsheader">
<caption>
Customer Details for <strong><? echo "$_SESSION['username']" ?></strong>

</caption>
<tr>
<td width="17%"><div align="right">First Name:</div></td>
<td width="26%" class="regulartextbold"><div align="left"><?=$ ?></div></td>
<td width="23%"><div align="right">E-Mail:</div></td>
<td width="34%" class="regulartextbold"><div align="left"><?=$ ?></div></td>
</tr>
<tr>
<td><div align="right">Last Name: </div></td>
<td class="regulartextbold"><div align="left"><?=$ ?></div></td>
<td><div align="right">Phone:</div></td>
<td><div align="left">
<input name="customers_phone" type="text" id="customers_phone" value="<?=$ ?>" class="regulartextbold">
</div></td>
</tr>
<tr>
<td><div align="right">Street:</div></td>
<td>
<div align="left">
<input name="customers_street_address" type="text" id="customers_street_address" value="<?=$ ?>" class="regulartextbold">
</div></td>
<td><div align="right">Mobile:</div></td>
<td><div align="left">
<input name="customers_phone2" type="text" id="customers_phone2" value="<?=$ ?>" class="regulartextbold">
</div></td>
</tr>
<tr>
<td><div align="right">City:</div></td>
<td>
<div align="left">
<input name="customers_city" type="text" id="customers_city" value="<?=$ ?>" class="regulartextbold">
</div></td>
<td><div align="right">Fax:</div></td>
<td><div align="left">
<input name="customers_fax" type="text" id="customers_fax" value="<?=$ ?>" class="regulartextbold">
</div></td>
</tr>
<tr>
<td><div align="right">State:</div></td>
<td>
<div align="left">
<input name="customers_state" type="text" id="customers_state" value="<?=$ ?>" class="regulartextbold">
</div></td>
<td><div align="right">Acct #:</div></td>
<td><div align="left">
<input name="egold_number" type="text" id="egold_number" value="<?=$ ?>" class="regulartextbold">
</div></td>
</tr>
<tr>
<td><div align="right">Zip:</div></td>
<td>
<div align="left">
<input name="customers_postcode" type="text" id="customers_postcode" value="<?=$ ?>" class="regulartextbold">
</div></td>
<td><div align="right">Acct Name:</div></td>
<td><div align="left">
<input name="egold_name" type="text" id="egold_name" value="<?=$ ?>" class="regulartextbold">
</div></td>
</tr>
<tr>
<td><div align="right">Country:</div></td>
<td>
<div align="left">
<input name="customers_country" type="text" id="customers_country" value="<?=$ ?>" class="regulartextbold">
</div></td>
<td><div align="right">Acct #:</div></td>
<td><div align="left">
<input name="ebullion_number" type="text" id="ebullion_number" value="<?=$ ?>" class="regulartextbold">
</div></td>
</tr>
<tr>
<td><div align="right">Phone:</div></td>
<td>
<div align="left">
<input name="customers_phone" type="text" id="customers_phone" value="<?=$ ?>" class="regulartextbold">
</div></td>
<td><div align="right">Acct Name:</div></td>
<td><div align="left">
<input name="ebullion_name" type="text" id="ebullion_name" value="<?=$ ?>" class="regulartextbold">
</div></td>
</tr>
<tr>
<td><div align="right">IP:</div></td>
<td class="regulartextbold"><div align="left"><?=$ ?></div></td>
<td><div align="right">Last Login: </div></td>
<td class="regulartextbold"><div align="left"><?=$ ?></div></td>
</tr>
<tr>
<td><div align="right">Registered:</div></td>
<td class="regulartextbold"><div align="left"><?=$ ?></div></td>
<td><div align="right">Modified:</div></td>
<td class="regulartextbold"><div align="left"><?=$ ?></div></td>
</tr>
<tr>
<td colspan="4"><div align="center">
<input name="save" type="submit" id="save" value="Save">
</div></td>
</tr>
</table>
</form>
<?
}
?>

Damon
06-15-2006, 08:17 PM
All i can see wrong is that you ended you funcito n after the html


<?
}
?>

and you did not use
echo to show the html so the html then is treated as
php

lansing
06-16-2006, 01:18 AM
You lost me except for the part about closing php after the form. I have done this on many pages & it works.

Kid Charming
06-16-2006, 01:30 AM
Which is line 85?

lansing
06-16-2006, 07:32 PM
I have deleted all code for when the form is submitted & just made an echo 'Form Submitted';...it works then, but when I add my form processing code back it goes back to that error above. There is a problem in my processing script that I just don't see.

Line 85 is the main else {} that belongs to this.
if(isset($_POST['save']))
{
//Code for when the form is submitted
}
else
{
//Code for when form isn't submitted
}

zorg222
06-16-2006, 10:48 PM
<?php
if(isset($_POST['save']))
{
$id = $_SESSION['id'];
$history_details = mysql_query("SELECT * FROM $customer_table WHERE customers= '$id'");
while ($line = mysql_fetch_array($history_details))
{
$customers = stripslashes($line["customers"]);
echo'';

$sql = mysql_query("INSERT INTO $history_table (customers)
VALUES($customers)")
or die (mysql_error());

if(!$sql)
{
die('There has been an error updating your account. Please contact the webmaster.');
}
else
{
$id = $_SESSION['id'];
$customers_street = addslashes($_POST['customers_street']);

$update_customer = ("UPDATE $customer_table SET customers_street = '$customers_street'
WHERE customers = '$id'");
$update_query = mysql_query($update_customer) or die(mysql_error());

if(!$update_query)
{
echo 'Error in updating customer contact information!';
echo 'Try again or contact support';
}
else
{
echo 'Customer contact information successfully updated!';
}
}
}


else
{
$id = $_SESSION['id'];
$customer_details = mysql_query("SELECT * FROM $customer_table WHERE customers_id= '$id' ");
while ($line = mysql_fetch_array($customer_details))
{
$customers = stripslashes($line["customers"]);
echo'';
}
}


?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" name="customer_details" id="customer_details">
<table width="100%" border="0" align="center" class="newsheader">
<caption>
Customer Details for <strong><? echo "$_SESSION['username']" ?></strong>

</caption>
<tr>
<td width="17%"><div align="right">First Name:</div></td>
<td width="26%" class="regulartextbold"><div align="left"><?=$ ?></div></td>
<td width="23%"><div align="right">E-Mail:</div></td>
<td width="34%" class="regulartextbold"><div align="left"><?=$ ?></div></td>
</tr>
<tr>
<td><div align="right">Last Name: </div></td>
<td class="regulartextbold"><div align="left"><?=$ ?></div></td>
<td><div align="right">Phone:</div></td>
<td><div align="left">
<input name="customers_phone" type="text" id="customers_phone" value="<?=$ ?>" class="regulartextbold">
</div></td>
</tr>
<tr>
<td><div align="right">Street:</div></td>
<td>
<div align="left">
<input name="customers_street_address" type="text" id="customers_street_address" value="<?=$ ?>" class="regulartextbold">
</div></td>
<td><div align="right">Mobile:</div></td>
<td><div align="left">
<input name="customers_phone2" type="text" id="customers_phone2" value="<?=$ ?>" class="regulartextbold">
</div></td>
</tr>
<tr>
<td><div align="right">City:</div></td>
<td>
<div align="left">
<input name="customers_city" type="text" id="customers_city" value="<?=$ ?>" class="regulartextbold">
</div></td>
<td><div align="right">Fax:</div></td>
<td><div align="left">
<input name="customers_fax" type="text" id="customers_fax" value="<?=$ ?>" class="regulartextbold">
</div></td>
</tr>
<tr>
<td><div align="right">State:</div></td>
<td>
<div align="left">
<input name="customers_state" type="text" id="customers_state" value="<?=$ ?>" class="regulartextbold">
</div></td>
<td><div align="right">Acct #:</div></td>
<td><div align="left">
<input name="egold_number" type="text" id="egold_number" value="<?=$ ?>" class="regulartextbold">
</div></td>
</tr>
<tr>
<td><div align="right">Zip:</div></td>
<td>
<div align="left">
<input name="customers_postcode" type="text" id="customers_postcode" value="<?=$ ?>" class="regulartextbold">
</div></td>
<td><div align="right">Acct Name:</div></td>
<td><div align="left">
<input name="egold_name" type="text" id="egold_name" value="<?=$ ?>" class="regulartextbold">
</div></td>
</tr>
<tr>
<td><div align="right">Country:</div></td>
<td>
<div align="left">
<input name="customers_country" type="text" id="customers_country" value="<?=$ ?>" class="regulartextbold">
</div></td>
<td><div align="right">Acct #:</div></td>
<td><div align="left">
<input name="ebullion_number" type="text" id="ebullion_number" value="<?=$ ?>" class="regulartextbold">
</div></td>
</tr>
<tr>
<td><div align="right">Phone:</div></td>
<td>
<div align="left">
<input name="customers_phone" type="text" id="customers_phone" value="<?=$ ?>" class="regulartextbold">
</div></td>
<td><div align="right">Acct Name:</div></td>
<td><div align="left">
<input name="ebullion_name" type="text" id="ebullion_name" value="<?=$ ?>" class="regulartextbold">
</div></td>
</tr>
<tr>
<td><div align="right">IP:</div></td>
<td class="regulartextbold"><div align="left"><?=$ ?></div></td>
<td><div align="right">Last Login: </div></td>
<td class="regulartextbold"><div align="left"><?=$ ?></div></td>
</tr>
<tr>
<td><div align="right">Registered:</div></td>
<td class="regulartextbold"><div align="left"><?=$ ?></div></td>
<td><div align="right">Modified:</div></td>
<td class="regulartextbold"><div align="left"><?=$ ?></div></td>
</tr>
<tr>
<td colspan="4"><div align="center">
<input name="save" type="submit" id="save" value="Save">
</div></td>
</tr>
</table>
</form>
<?php
}
?>

I think there was just some issues with the brackets getting mixed up. I went through and fixed everything. In the future, you may want to keep each set of brackets "lined up" vertically to avoid confusion. An IDE that highlights bracket sets may help as well. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum