Jump to content


Photo

Strange error in code


  • Please log in to reply
5 replies to this topic

#1 ambrennan

ambrennan
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 07 April 2006 - 01:06 AM

I am using the folowing code to search a db and bring back results but am getting the following error
"Parse error: parse error, unexpected $ in C:\Program Files\xampp\htdocs\search-example2.php on line 47"
but my code only has 45 lines in it - What am I doing wrong?

<?php require_once('Connections/xxx.php'); ?>

<?php
    if($_GET['action']=="xxxxxxxx")
    {
        $arrDate_day=$_POST['arrDate_day'];
        $arrDate_mon=$_POST['arrDate_mon'];
        $arrDate_year=$_POST['arrDate_year'];
        $RoomType=$_POST['RoomType'];
        $SmokingYesNo=$_POST['SmokingYesNo'];
        $deptDate_day=$_POST['deptDate_day'];
        $deptDate_mon=$_POST['deptDate_mon'];
        $deptDate_year=$_POST['deptDate_year']; 
        
        $arrivalday=$arrDate_year."-".$arrDate_mon."-".$arrDate_day;
        $departuredate=$deptDate_year."-".$deptDate_mon."-".$deptDate_day;
        
        if($arrivalday >= $departuredate)
    {
        echo "<h2>Your arrival date cannot be greater than your departure date</h2>";
        
    $query = "SELECT * FROM `room_desc_t` t LEFT JOIN `reservations_t` r WHERE t.room_type='{$RoomType}' 
    AND room_smoking='{$SmokingYesNo}' AND r.res_arrival_date >= '{$Arrival}' AND r.res_departure_date < '{$Departure}'";
    $result = mysql_query($query) or die("Unable to execute query: ".mysql_error()); //(mysql_error());
    
    if (mysql_num_rows($result) > 0)
    {
        echo"<table cellpadding=\"2\" cellspacing=\"2\" border=\"2\">";
        while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) 
        {
            echo"<tr>";
            foreach ($line as $col_value) 
            {
                echo"<td>$col_value</td>";
            }
            echo"</tr>";
        }
        echo"</table>";
    }
    else
    {
        echo"<p>There is no availability for these dates</p>";
    }
?>


#2 earl_dc10

earl_dc10
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 07 April 2006 - 02:11 AM

it may be to the fact that you have 6 opening brackets, but only 4 closing ones
got a problem? Google helps many of those in need

#3 ambrennan

ambrennan
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 07 April 2006 - 02:49 AM

[!--quoteo(post=362415:date=Apr 6 2006, 09:11 PM:name=earl_dc10)--][div class=\'quotetop\']QUOTE(earl_dc10 @ Apr 6 2006, 09:11 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
it may be to the fact that you have 6 opening brackets, but only 4 closing ones
[/quote]

Thanks for that!
I spotted the missing brackets when I went back working on the code and put them in but I'm still getting the same weird error. I've only started php and am likely to make silly mistakes - any more ideas on what could be wrong.

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 07 April 2006 - 04:15 AM

Please post you're corrected code.

Ken

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 07 April 2006 - 10:11 AM

I see you indent your code, but in an irregular way so your code blocks dont line up. You should of added two closing braces just before the closing PHP tag (?>). Here is you corrected code:
<?php require_once('Connections/xxx.php');

if($_GET['action'] == "xxxxxxxx")
{
    $arrDate_day   = $_POST['arrDate_day'];
    $arrDate_mon   = $_POST['arrDate_mon'];
    $arrDate_year  = $_POST['arrDate_year'];
    $RoomType      = $_POST['RoomType'];
    $SmokingYesNo  = $_POST['SmokingYesNo'];
    $deptDate_day  = $_POST['deptDate_day'];
    $deptDate_mon  = $_POST['deptDate_mon'];
    $deptDate_year = $_POST['deptDate_year'];

    $arrivalday    = $arrDate_year . "-" . $arrDate_mon . "-" . $arrDate_day;
    $departuredate = $deptDate_year . "-" . $deptDate_mon . "-" . $deptDate_day;

    if($arrivalday >= $departuredate)
    {
        echo "<h2>Your arrival date cannot be greater than your departure date</h2>";

        $query = "SELECT * FROM `room_desc_t` t LEFT JOIN `reservations_t` r WHERE t.room_type='{$RoomType}' AND
        room_smoking='{$SmokingYesNo}' AND r.res_arrival_date >= '{$Arrival}' AND r.res_departure_date < '{$Departure}'";

        $result = mysql_query($query) or die("Unable to execute query: ".mysql_error()); //(mysql_error());

        if (mysql_num_rows($result) > 0)
        {
            echo"<table cellpadding=\"2\" cellspacing=\"2\" border=\"2\">";

            while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
            {
                echo"<tr>";

                foreach ($line as $col_value)
                {
                    echo"<td>$col_value</td>";
                }

                echo"</tr>";
            }

            echo"</table>";
        }
        else
        {
            echo"<p>There is no availability for these dates</p>";
        }
    } //this one and the one below it was missing, causeing the error.
}
?>


#6 ambrennan

ambrennan
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 07 April 2006 - 11:38 AM

[!--quoteo(post=362472:date=Apr 7 2006, 05:11 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 7 2006, 05:11 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I see you indent your code, but in an irregular way so your code blocks dont line up. You should of added two closing braces just before the closing PHP tag (?>). Here is you corrected code:
<?php require_once('Connections/xxx.php');

if($_GET['action'] == "xxxxxxxx")
{
    $arrDate_day   = $_POST['arrDate_day'];
    $arrDate_mon   = $_POST['arrDate_mon'];
    $arrDate_year  = $_POST['arrDate_year'];
    $RoomType      = $_POST['RoomType'];
    $SmokingYesNo  = $_POST['SmokingYesNo'];
    $deptDate_day  = $_POST['deptDate_day'];
    $deptDate_mon  = $_POST['deptDate_mon'];
    $deptDate_year = $_POST['deptDate_year'];

    $arrivalday    = $arrDate_year . "-" . $arrDate_mon . "-" . $arrDate_day;
    $departuredate = $deptDate_year . "-" . $deptDate_mon . "-" . $deptDate_day;

    if($arrivalday >= $departuredate)
    {
        echo "<h2>Your arrival date cannot be greater than your departure date</h2>";

        $query = "SELECT * FROM `room_desc_t` t LEFT JOIN `reservations_t` r WHERE t.room_type='{$RoomType}' AND
        room_smoking='{$SmokingYesNo}' AND r.res_arrival_date >= '{$Arrival}' AND r.res_departure_date < '{$Departure}'";

        $result = mysql_query($query) or die("Unable to execute query: ".mysql_error()); //(mysql_error());

        if (mysql_num_rows($result) > 0)
        {
            echo"<table cellpadding=\"2\" cellspacing=\"2\" border=\"2\">";

            while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
            {
                echo"<tr>";

                foreach ($line as $col_value)
                {
                    echo"<td>$col_value</td>";
                }

                echo"</tr>";
            }

            echo"</table>";
        }
        else
        {
            echo"<p>There is no availability for these dates</p>";
        }
    } //this one and the one below it was missing, causeing the error.
}
?>
[/quote]

Thanks,

Will try this out tonight and hopefully have success - Thanks again





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users