Jump to content


Photo

Parse Error?


  • Please log in to reply
7 replies to this topic

#1 sKunKbad

sKunKbad
  • Members
  • PipPipPip
  • Advanced Member
  • 1,832 posts
  • LocationTemecula, CA, USA

Posted 05 April 2006 - 12:14 AM

I'm getting this error:

Parse error: parse error, unexpected T_STRING in /testbusiness_search.php on line 19, and I can't figure it out.

Line 19 is
if ($value1 != "All Christian Business" AND $value2 != "All Cities")

I'm pretty sure once this is taken care of I'm going to have some more problems with this page, specifically the
$num_rows = mysql_num_rows ($sql);

Here is the surrounding php:

<?php
include("./includes/genesis.php");

$value1 = "$_GET[subType]";
$value2 = "$_GET[city]";

echo "<h2>$subType in $city</h2>";

if (!isset($_GET['page'])){
           $page = 1;
           } ELSE {
           $page = $_GET['page'];
        }
        
        $max_results = 5;
        $from = (($page * $max_results) - $max_results);


if ($value1 != "All Christian Business" AND $value2 != "All Cities")
{$sql = mysql_query("SELECT * FROM localdirectory WHERE subType = '$value1' AND city = '$value2' ORDER BY name LIMIT $from, $max_results"); }

if ($value1 == "All Christian Business" AND $value2 != "All Cities")
{$sql = mysql_query("SELECT * FROM localdirectory WHERE city = '$value2' ORDER BY name LIMIT $from, $max_results"; }

if ($value1 != "All Christian Business" AND $value2 == "All Cities")
{$sql = mysql_query("SELECT * FROM localdirectory WHERE subType = '$value1' ORDER BY name LIMIT $from, $max_results"; }

if ($value1 == "All Christian Business" AND $value2 == "All Cities")
{$sql = mysql_query("SELECT * FROM localdirectory ORDER BY name LIMIT $from, $max_results";}

if ($value1 == "All Christian Business" AND $value2 == "Riverside County")
{$sql = mysql_query("SELECT * FROM localdirectory ORDER BY name LIMIT $from, $max_results";}

if ($value1 != "All Christian Business" AND $value2 == "Riverside County")
{$sql = mysql_query("SELECT * FROM localdirectory WHERE subtype = '$value1' ORDER BY name LIMIT $from, $max_results";}


$num_rows = mysql_num_rows ($sql);

if ($num_rows == 0) {echo "<p id=\"warning\">There are currently no matches for your search in the database.<br/>\nPlease try widening your search by choosing \"All Cities\" or \"Riverside County\"<br/>\n<a href=\"http://www.iamsent.com/directory.php\">Go Back</a></p>";}  ELSE {                                       

while ($row = mysql_fetch_array($sql))                          
extract ($row);                                                           
if($type == "business") { //This is where the business listings get called up by the if statement
echo "<div class=\"sponsor\">";}
if($sponsorStatus == "yes"){echo "<img src=\"images/sponsor.jpg\" alt=\"this Christian owned business is a site sponsor\"/>";} else {echo " ";}
echo "</div>";
echo "<div class=\"listing\">";
echo "<strong>$name</strong>";
if($address != ""){echo "<br/>\n$address";}
if($city != ""){echo "<br/>\n$city",", ";}
if($st != ""){echo "$st"," ";}
if($zip != ""){echo "$zip";}
if($teleNumber != ""){echo "<br/>\n$teleNumber";}
if($webAddress != ""){echo "<br/>\nwebsite: <a href=\"$webAddress\">$webAddress</a>";}
if($email != ""){echo "<br/>\nemail: <a href=\"mailto:$email\">$email</a>";}
echo "</div>\n";?><div class="hrule76"> </div><?php
echo "\n";
}
if ($value1 != "All Christian Business" && $value2 != "All Cities"){
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE subType ='$value1' AND city = '$value2'"),0);
}
if ($value1 == "All Christian Business" && $value2 != "All Cities"){
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE type = 'business' AND city ='$value2'"),0);
}
if ($value1 != "All Christian Business" && $value2 == "All Cities"){
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE subType = '$value1' "),0);
}
if ($value1 == "All Christian Business" && $value2 == "All Cities"){
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE type = 'business' "),0);
}
if ($value1 == "All Christian Business" && $value2 == "Riverside County"){
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE type = 'business' "),0);
}
if ($value1 != "All Christian Business" && $value2 == "Riverside County"){
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE subType = '$value1' "),0);
}

$total_pages = ceil($total_results / $max_results);
           
echo "<center><br/><strong>Page<br />";
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&subType=$value1&city=$value2\"><<Previous</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&subType=$value1&city=$value2\">$i</a> ";
    }
}
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&subType=$value1&city=$value2\">Next>></a>";
}
echo "</strong></center>";
echo "<p><a href=\"http://www.iamsent.com/directory.php\">Back To Directory Home</a></p>";
echo "<p><a href=\"http://www.iamsent.com/directory.php\">Go Back</a></p>";
?>


Thanks for your help.
Brian's Web Design - Temecula

Freedom is only available through death.

#2 dcro2

dcro2
  • Members
  • PipPipPip
  • Advanced Member
  • 489 posts

Posted 05 April 2006 - 12:34 AM

I'm pretty sure it has something to do with how you get the value of $value1 and $value2:
$value1 = "$_GET[subType]";
$value2 = "$_GET[city]";
To get a value from an array ($_GET) you need to put it inside curly brackets ({}) while inside quotes. You also don't need to put it inside quotes, if it's a string, then the $value variable is going to be a string also.
$value1 = $_GET[subType];
$value2 = $_GET[city];


#3 sKunKbad

sKunKbad
  • Members
  • PipPipPip
  • Advanced Member
  • 1,832 posts
  • LocationTemecula, CA, USA

Posted 05 April 2006 - 12:43 AM

[!--quoteo(post=361786:date=Apr 4 2006, 05:34 PM:name=dcro2)--][div class=\'quotetop\']QUOTE(dcro2 @ Apr 4 2006, 05:34 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I'm pretty sure it has something to do with how you get the value of $value1 and $value2:
$value1 = "$_GET[subType]";
$value2 = "$_GET[city]";
To get a value from an array ($_GET) you need to put it inside curly brackets ({}) while inside quotes. You also don't need to put it inside quotes, if it's a string, then the $value variable is going to be a string also.
$value1 = $_GET[subType];
$value2 = $_GET[city];
[/quote]

No, that didn't make any difference. Thanks for trying though.
Brian's Web Design - Temecula

Freedom is only available through death.

#4 dcro2

dcro2
  • Members
  • PipPipPip
  • Advanced Member
  • 489 posts

Posted 05 April 2006 - 12:52 AM

Besides that, after the first condition and $sql, you are forgetting to put a ")" to the end of mysql_query()

#5 sKunKbad

sKunKbad
  • Members
  • PipPipPip
  • Advanced Member
  • 1,832 posts
  • LocationTemecula, CA, USA

Posted 05 April 2006 - 01:08 AM

[!--quoteo(post=361790:date=Apr 4 2006, 05:52 PM:name=dcro2)--][div class=\'quotetop\']QUOTE(dcro2 @ Apr 4 2006, 05:52 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Besides that, after the first condition and $sql, you are forgetting to put a ")" to the end of mysql_query()
[/quote]

Thanks for pointing that out. I am really a super n00bie to php, so I need all the help I can get!

I'm still hoping somebody can figure out my original error.
Brian's Web Design - Temecula

Freedom is only available through death.

#6 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 05 April 2006 - 03:59 AM

the problem is that you cannot use "AND" in conditionals. the equivalent of AND in PHP is "&&". try replacing AND with && and see if you continue getting the parse error.

EDIT: ignore me. ken is right. it may be that you are using uppercase rather than lowercase. doubt it though.

#7 kenrbnsn

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

Posted 05 April 2006 - 04:15 AM

Actually, you can use "and" and "or" in conditional statements as explained in the [a href=\"http://us3.php.net/manual/en/language.operators.logical.php\" target=\"_blank\"]manual[/a].

Ken

#8 sKunKbad

sKunKbad
  • Members
  • PipPipPip
  • Advanced Member
  • 1,832 posts
  • LocationTemecula, CA, USA

Posted 05 April 2006 - 06:06 AM

Actually, I had many errors that I have worked out on this page in the last couple of hours. I think my problem is that I am staring at code for like 16 hour a day, and sometimes my brain is just fried. That and I am new to php doesn't help.

The main issue here was that I was trying to call a field from the database that didn't even exist. *kicks self for you guys* So yeah, I am an idiot.

Right now everything is working pretty smoothly, except for a specific search type, specifically searches where the business type not equaling "All businesses" but equaling "All cities". Also, I have a business type called "Sewing, Quilting, & Embroidery", and it isn't working at all. I think it has something to do with the commas and the amp character, but unless somebody has a quick fix for that it's gonna have to wait till tomorrow. Let me show you what I have now:

<?php
$value1 = isSet ($_GET['subType']) ? $_GET['subType'] : NULL;
$value2 = isSet ($_GET['city']) ? $_GET['city'] : NULL;

echo "<h2>$subType in $city</h2>";

if (!isset($_GET['page'])){
           $page = 1;
           } ELSE {
           $page = $_GET['page'];
        }
        
        $max_results = 1; //HERE IS WHERE YOU SAY HOW MANY ROWS OF RESULTS PER PAGE YOU WANT
        $from = (($page * $max_results) - $max_results);
        
//BEGIN RESULTS QUERIES
if ($value1 != "All Christian Businesses" && $value2 != "All Cities")
{$sql = mysql_query("SELECT * FROM localdirectory WHERE subType = '$value1' && city = '$value2' ORDER BY name LIMIT $from, $max_results"); }

if ($value1 == "All Christian Businesses" && $value2 != "All Cities")
{$sql = mysql_query("SELECT * FROM localdirectory WHERE type = 'business' && city = '$value2' ORDER BY name LIMIT $from, $max_results"); }

if ($value1 != "All Christian Businesses" && $value2 == "All Cities")
{$sql = mysql_query("SELECT * FROM localdirectory WHERE subType = '$value1' ORDER BY name LIMIT $from, $max_results"); }

if ($value1 == "All Christian Businesses" && $value2 == "All Cities")
{$sql = mysql_query("SELECT * FROM localdirectory WHERE type = 'business' ORDER BY name LIMIT $from, $max_results");}

if ($value1 == "All Christian Businesses" && $value2 == "Riverside County")
{$sql = mysql_query("SELECT * FROM localdirectory WHERE type = 'business' ORDER BY name LIMIT $from, $max_results" );}

if ($value1 != "All Christian Businesses" && $value2 == "Riverside County")
{$sql = mysql_query("SELECT * FROM localdirectory WHERE subtype = '$value1' ORDER BY name LIMIT $from, $max_results");}
//END RESULTS QUERIES

//COUNT RESULTS AND OUTPUT NO MATCH MESSAGE IF NONE FOUND
$num_rows = mysql_num_rows ($sql);
if ($num_rows == 0) 
    {
    echo "<p id=\"warning\">There are currently no matches for your search in the database.<br/>\nPlease try widening your search by choosing \"All Cities\" or \"Riverside County\"<br/>\n<a href=\"http://www.iamsent.com/directory.php\">Go Back</a></p>";
    }ELSE{                                       
        while ($row = mysql_fetch_array($sql))  //OUTPUT MATCHES FOR COUNT NOT ZERO
            {                          
            extract ($row);                                                           
            if($type == "business") { //This is where the business listings get called up by the if statement
            echo "<div class=\"sponsor\">";}
            if($sponsorStatus == "yes"){echo "<img src=\"images/sponsor.jpg\" alt=\"this Christian owned business is a site sponsor\"/>";} else {echo " ";}
            echo "</div>";
            echo "<div class=\"listing\">";
            echo "<strong>$name</strong>";
            if($address != ""){echo "<br/>\n$address";}
            if($city != ""){echo "<br/>\n$city",", ";}
            if($st != ""){echo "$st"," ";}
            if($zip != ""){echo "$zip";}
            if($teleNumber != ""){echo "<br/>\n$teleNumber";}
            if($webAddress != ""){echo "<br/>\nwebsite: <a href=\"$webAddress\">$webAddress</a>";}
            if($email != ""){echo "<br/>\nemail: <a href=\"mailto:$email\">$email</a>";}
            echo "</div>\n";?><div class="hrule76"> </div><?php
            echo "\n";
            }
         }

//COUNT TOTAL RESULTS FOR PAGINATION
if ($value1 == "All Christian Businesses" && ($value2 == "All Cities" OR $value2 == "Riverside County"))
{
    $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE type = 'business' "),0);
}
elseif ($value1 != "All Christian Businesses" && ($value2 != "All Cities" OR $value2 != "Riverside County"))
{
    $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE subType ='$value1' AND city = '$value2' "),0);
}
elseif ($value1 != "All Christian Businesses" && ($value2 == "All Cities" OR $value2 == "Riverside County"))
{
    $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE subType = '$value1' "),0);
}
elseif ($value1 == "All Christian Businesses" && ($value2 != "All Cities" OR $value2 != "Riverside County"))
{
    $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM localdirectory WHERE type = 'business' AND city ='$value2' "),0);
}

//DIVIDE TOTAL RESULTS BY MAX RESULTS PER PAGE TO DETERMINE ACTUAL NUMBER OF PAGES TO BE MADE
$total_pages = ceil($total_results / $max_results);

//NOW THAT ACTUAL NUMBER OF PAGES IS KNOWN - NEXT, PREVIOUS, AND INDIVIDUAL PAGE LINKS CAN BE MADE           
echo "<center><br/><strong>Page<br />";
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&subType=$value1&city=$value2\"><<Previous</a> ";
}

  for($i = 1; $i <= $total_pages; $i++)
    {
    if(($page) == $i)
        {
        echo "$i ";
        }else{
        echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&subType=$value1&city=$value2\">$i</a> ";
        }
    }
    if($page < $total_pages)
        {
        $next = ($page + 1);
        echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&subType=$value1&city=$value2\">Next>></a>";
        }
echo "</strong></center>";

echo "<p><a href=\"http://www.iamsent.com/directory.php\">Back To Directory Home</a></p>";

?>

PS. I have max results set to 1 for testing purposes.

Thanks!!
Brian's Web Design - Temecula

Freedom is only available through death.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users