Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts

    If{} else{} statement help!!

    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 Code:
    <?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>
        <?
        
    }
        
    ?>
    Last edited by lansing; 06-15-2006 at 01:33 PM.

  • #2
    New Coder
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    All i can see wrong is that you ended you funcito n after the html

    PHP Code:
        <?
        
    }
        
    ?>
    and you did not use
    PHP Code:
    echo 
    to show the html so the html then is treated as
    PHP Code:
    php 

  • #3
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    You lost me except for the part about closing php after the form. I have done this on many pages & it works.

  • #4
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Which is line 85?

  • #5
    Regular Coder
    Join Date
    Dec 2005
    Posts
    346
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.
    PHP Code:
    if(isset($_POST['save']))
    {
    //Code for when the form is submitted
    }
    else
    {
    //Code for when form isn't submitted


  • #6
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post
    PHP Code:
    <?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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •