Jump to content

[SOLVED] parse error in nested if statement. i canNOT figure it out...


boo_lolly

Recommended Posts

here's the error:

Parse error: parse error, expecting `T_VARIABLE' or `'$'' in editCouple.php on line 38

 

here's my code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><TITLE>Edit Couple</TITLE></HEAD>

<BODY>
<CENTER>
<?php $location = "<B>Edit Couple</B>"; ?>

<TABLE BORDER="1" WIDTH="850" CELLPADDING="20">
        <TR>
                <TD WIDTH="%50" ALIGN="center"><H1>The Very Thing Gifts</H1>
                <?php echo $location; ?>
                <form method="POST" action="admin1.php?action=view_all">
                <input type="SUBMIT" value="View All">
                </form>
                </TD>
                <TD><?php include "admin_search.inc" ?></TD>
        </TR>
</TABLE><BR>

<HR WIDTH="300"><BR>

<TABLE WIDTH="750">
        <TR>
                <TD>
<?php
        /*connect to database*/
        @ $db = mysql_connect("xxx", "xxx", "xxx");
        if(!$db){
                echo "Error: Could not connect to the database. Please try again later.";
                exit;
        }
        /*select database*/
        mysql_select_db("my_db", $db);

        /*update couple information*/
        if(isset($_POST)){
                if(empty(trim($_POST['brideLname'])) && empty(trim($_POST['groomLname']))){  //<-- line 38
                        echo "<div align=\"center\"><font color=\"ff0000\">Please enter a last name for Bride <i>and</i> Groom.</font></div>\n";
                }else{
                /*define function to prevent sql injection*/
                        function clean($var){
                                return $var = mysql_real_escape_string(trim($var));
                        }
                /*apply clean() to each $_POST variable*/
                        array_walk($_POST, 'clean');

                        $sql = "UPDATE my_search_table
                                SET brideFname = '". $_POST['brideFname'] ."',
                                    brideLname = '". $_POST['brideLname'] ."',
                                    groomFname = '". $_POST['groomFname'] ."',
                                    groomLname = '". $_POST['groomLname'] ."',
                                    event_month = '". $_POST['event_month'] ."',
                                    event_day = '". $_POST['event_day'] ."',
                                    event_year = '". $_POST['event_year'] ."',
                                    ship_add = '". $_POST['ship_add'] ."',
                                    ship_city = '". $_POST['ship_city'] ."',
                                    ship_state = '". $_POST['ship_state'] ."',
                                    ship_zip = '". $_POST['ship_zip'] ."'
                                WHERE uID = '". $_GET['id'] ."'";
                        mysql_query($sql);

                /*confirm/disconfirm update*/
                        echo "<div align=\"center\">\n";
                        if(!mysql_query($sql)){
                                echo "<font color=\"ff0000\">Revisions were not successful. Please try again.</font>\n";
                        }else{
                                echo "<font color=\"339933\">Updated information was successful</font>\n";
                        }
                        echo "</div>\n";

                /*unset $_POST variables*/
                        unset($_POST);
                }
        }

        /*query database*/
        $sql = mysql_query("SELECT * FROM my_search_table WHERE uID = '". $_GET['id'] ."'") or die(mysql_error());
        $row = mysql_fetch_array($sql);

        /*pre-populate input fields with values from the database.*/
        echo "<TABLE WIDTH=\"700\"><TR><TD>\n";
        echo "<form action=\"editCouple.php?id=". $_GET['id'] ."\" method=\"post\">\n";
        echo "<div align=\"center\"><b>Bride's Name</div>\n";
        echo "<B>First:</B> <input type=\"text\" name=\"brideFname\" value=\"". $row['brideFname'] ."\" size=\"25\"><br />\n";
        echo "<B>Last:</B> <input type=\"text\" name=\"brideLname\" value=\"". $row['brideLname'] ."\" size=\"25\"><br /><br />\n";
        echo "</TD>\n";

        echo "<TD>\n";
        echo "<div align=\"center\"><b>Groom's Name</div>\n";
        echo "<B>First:</B> <input type=\"text\" name=\"groomFname\" value=\"". $row['groomFname'] ."\" size=\"25\"><br />\n";
        echo "<B>Last:</B> <input type=\"text\" name=\"groomLname\" value=\"". $row['groomLname'] ."\" size=\"25\"><br /><br />\n";
        echo "</TD></TR>\n";

        echo "<TR><TD COLSPAN=\"2\">\n";
        echo "<b>Event Date:</b> \n";
        /*define months array*/
        $array_month = array("January" => "01", "February" => "02", "March" => "03",
                             "April" => "04", "May" => "05", "June" => "06",
                             "July" => "07", "August" => "08", "Steptember" => "09",
                             "October" => "10", "November" => "11", "December" => "12");
        echo "<SELECT NAME=\"event_month\">\n";
        /*prepopulate the dropdown menu for the event month*/
        foreach($array_month as $key => $val){
                echo "<OPTION VALUE=\"". $val ."\"". (($val == $row['event_month']) ? (" SELECTED") : ("")) .">". $key ."\n";
        }
        echo "</SELECT>\n";

        /*define days array*/
        $days = range(1, 31);
        echo"<SELECT NAME=\"event_day\">\n";
        /*prepopulate the dropdown menu for the event day*/
        foreach($days as $day){
                if($day >= 1 && $day <= 9){
                        $day = "0". $day;
                }
                echo "<OPTION VALUE=\"". $day ."\"". (($day == $row['event_day']) ? (" SELECTED") : ("")) .">". $day ."\n";
        }
        echo "</SELECT>\n";

        /*define years array*/
        $years = range(2006, 2015);
        echo "<SELECT NAME=\"event_year\">\n";
        /*prepopulate the dropdown menu for the event year*/
        foreach($years as $year){
                echo "<OPTION VALUE=\"". $year ."\"". (($year == $row['event_year']) ? (" SELECTED") : ("")) .">". $year ."\n";
        }
        echo "</SELECT>\n";
?>
                </TD>
        </TR>
        <TR>
                <TD COLSPAN="2"><BR>
<?php
        echo "<TABLE WIDTH=\"500\"><TR><TD COLSPAN=\"2\">\n";
        echo "<B>Shipping Information:</B>\n";
        echo "</TD></TR><TR><TD align=\"right\" valign=\"top\">\n";
        echo "<B>Street:</B> <input type=\"text\" name=\"ship_add\" value=\"". $row['ship_add'] ."\" size=\"30\"><br />\n";
        echo "<B>City:</B> <input type=\"text\" name=\"ship_city\" value=\"". $row['ship_city'] ."\" size=\"30\"><br />\n";
        echo "</TD><TD align=\"right\" valign=\"top\">\n";
        echo "<B>State:</B> <input type=\"text\" name=\"ship_state\" value=\"". $row['ship_state'] ."\" size=\"15\"><br />\n";
        echo "<B>Zip Code:</B> <input type=\"text\" name=\"ship_zip\" value=\"". $row['ship_zip'] ."\" size=\"15\"><br /><br />\n";
        echo "</TD></TR></TABLE>\n";
?>
                </TD>
        </TR>
        <TR>
                <TD COLSPAN="2">
<CENTER>
<TABLE WIDTH="500">
        <TR>
                <TD VALIGN="top">
                <input type="submit" value="Save"></form></TD>
                <TD VALIGN="top">
                <form method="post" action=updateRegistry.php?regID=<?php echo $_GET['id']; ?>>
                <input type="submit" value="Continue to Registry >>"></form></TD>
        </TR>
</TABLE>
</CENTER>
                </TD>
        </TR>
</TABLE>

</BODY>
</HTML>

 

where am i going wrong?[/code]

Link to comment
Share on other sites

You have an error at line 46 as well...

 

 array_walk($_POST), 'clean');

should be:

 array_walk($_POST, 'clean');

 

As far as the error at line 38, here is what Zend Studio gives as an error description:

 

Compile Warning: Can't use function return value in write context (line 38)

 

This doesn't return an error:

 

$bln = trim($_POST['brideLname']);
        		$gln = trim($_POST['brideLname']);
        	
                if (empty($bln) && empty($gln)){  //<-- line 38
                        echo "<div align=\"center\"><font color=\"ff0000\">Please enter a last name for Bride <i>and</i> Groom.</font></div>\n";
                }else{

 

@Daniel0...you are missing 2 closing parenthesis in your recommendation.

Link to comment
Share on other sites

thank you both for the quick replies! hitman, why would that be any different from what i have in my if statement? php can't be that janky... there's GOTTA be another reason... am i right?

 

i tried it and it worked... but why WON'T it work the way i had coded it orginally? there's really no difference that i can see.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.