Jump to content

Parse Error?


sKunKbad

Recommended Posts

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:

[code]<?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>";
?>

[/code]

Thanks for your help.
Link to comment
https://forums.phpfreaks.com/topic/6616-parse-error/
Share on other sites

I'm pretty sure it has something to do with how you get the value of $value1 and $value2:
[code]$value1 = "$_GET[subType]";
$value2 = "$_GET[city]";[/code]
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.
[code]$value1 = $_GET[subType];
$value2 = $_GET[city];[/code]
Link to comment
https://forums.phpfreaks.com/topic/6616-parse-error/#findComment-24030
Share on other sites

[!--quoteo(post=361786:date=Apr 4 2006, 05:34 PM:name=dcro2)--][div class=\'quotetop\']QUOTE(dcro2 @ Apr 4 2006, 05:34 PM) [snapback]361786[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I'm pretty sure it has something to do with how you get the value of $value1 and $value2:
[code]$value1 = "$_GET[subType]";
$value2 = "$_GET[city]";[/code]
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.
[code]$value1 = $_GET[subType];
$value2 = $_GET[city];[/code]
[/quote]

No, that didn't make any difference. Thanks for trying though.
Link to comment
https://forums.phpfreaks.com/topic/6616-parse-error/#findComment-24033
Share on other sites

[!--quoteo(post=361790:date=Apr 4 2006, 05:52 PM:name=dcro2)--][div class=\'quotetop\']QUOTE(dcro2 @ Apr 4 2006, 05:52 PM) [snapback]361790[/snapback][/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.
Link to comment
https://forums.phpfreaks.com/topic/6616-parse-error/#findComment-24037
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/6616-parse-error/#findComment-24074
Share on other sites

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:

[code]<?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>";

?>[/code]

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

Thanks!!
Link to comment
https://forums.phpfreaks.com/topic/6616-parse-error/#findComment-24098
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.