ok so this is what im trying to do. this is a products page and the products diplay but i want to create a filter so if they want to view only the in this case tvs that are sony they use the from that is in the coding to select what brand and then press submit and the form will send to the same page and the if statment will look for the one that states if variable(brand) > 0 then use the following if statment but i keep getting this problem

Parse error: syntax error, unexpected T_VARIABLE in /home/content/u/v/c/uvc2008/html/tv.php on line 21

help me please i'm confused

<?php
$dbHost = "UVCvoldb.db.3892101.hostedresource.com";
$dbUser = "UVCvoldb";
$dbPass = "UVCvol2008";
$dbDatabase = "UVCvoldb";

$Type=($_GET['Type']);
$Brand=($_GET['Brand']);
$Size=($_GET['Size']);
$Price=($_GET['Price']);
$Model=($_GET['Model']);

 $db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");



mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");

if ( (strlen($Type) > 0) && (strlen($Brand) > 0  ) && (strlen($Size) > 0  ) && (strlen($Price) > 0 ) )
{
$sql= "select * from PRODUCTS where Type="$Type" and Brand="$Brand" and Size="$Size" and Price="$Price" order by ProductID");
}

elseif ( (strlen($Type) > 0) && (strlen($Brand) > 0  ) && (strlen($Size) > 0  )  )
{
$sql= "select * from PRODUCTS where Type="$Type" and Brand="$Brand" and Size="$Size" order by ProductID");
}

elseif ( (strlen($Type) > 0) && (strlen($Brand) > 0  )  )
{
$sql= "select * from PRODUCTS where Type="$Type" and Brand="$Brand"  order by ProductID");
}

elseif ( (strlen($Type) > 0)   )
{
$sql= "select * from PRODUCTS where Type="$Type"  order by ProductID");
}

elseif ( (strlen($Brand) > 0)   )
{
$sql= "select * from PRODUCTS where Brand="$Brand"  order by ProductID");
}

elseif ( (strlen($Size) > 0)   )
{
$sql= "select * from PRODUCTS where Size="$Size"  order by ProductID ");
}

elseif ( (strlen($Price) > 0)   )
{
$sql= "select * from PRODUCTS where Price="$Price"  order by ProductID");
}

elseif ( (strlen($Model) > 0)   )
{
$sql= "select * from PRODUCTS where Model="$Model"  order by ProductID");
}

else 
{
$sql= "select * from PRODUCTS";
}


$result=mysql_query("$sql");

//filter table start
echo <<<END

<form action="products.php?Category=TV" meathod="GET">

<input type="hidden" value="TV" Name="Category">

<table width="969" border="1">

<tr>

<td>Type</td>

<td><select name="Type"><option selected="selected" value="">None</option>

<option Value="Flat Screen Plasma">Flat Screen Plasma</option>

<option Value="Flat Screen LCD"> Flat Screen LCD</option>

  </select>

</td>

<td>Brand</td>

<td><select  name="Brand"><option selected="selected" value="">None</option>

<option Value="Sony">Sony</option>

<option Value="LG"> LG</option>

  </select>

</td>

<td>Size</td>

<td><select name="Size"><option selected="selected" value="">None</option>

<option Value="26">26</option>

<option Value="34"> 34</option>

  </select>

</td>

<td>Price</td>

<td><select  name="Price"><option selected="selected" value="">None</option>

<option Value="$200-$300">$200-$300</option>

<option Value="$300-$500"> $300-$500</option>

<option Value="$500-$1500"> $500-$1500</option>

  </select>

</td>

<td>Model</td>

<td><input type="text" Name="Model"></td>

<td><input type="Submit" name="submit" value="submit"><input type="reset" name="reset" value="Clear"></td>

</tr>

</table>

</form>

END;

// filter table end



while($row = mysql_fetch_array( $result )) {

	// displaying products 

    $Image=$row['Image'];

	$Name=$row['Name'];

	$ModelNum =$row['Model#'];

	$ProductID=$row['ProductID'];

	echo "<table width=969>";

echo "<tr><td rowspan=4 width=201>";

echo "<form target=_blank action=viewproduct.php method=post><input type=hidden value=$ProductID name=ProductID />";

echo "<input type=image src=$Image width=201 heigth=144> </form>";

echo "</td><td colspan=2>$Name</td></tr>";

echo "<tr><td>Model#:$ModelNum</td><td>Product ID: $ProductID</td></tr>";

echo "<tr><td colspan=2>If You are interested in this product click (I Want IT Button). REMEMBER only submite once, if you submit more then one time you will be discualified from this product.<form action=addmembid.php method=post><input type=hidden value=$ProductID name=ProductID /><input type=submit name=submit value='I Want It'></form></td></tr>";

echo "</table>";

echo "<hr width=969>";

}



?>

</div>

</center>

Recommended Answers

All 3 Replies

You're missing an ending parenthesis on almost all of those conditions. You don't need to disambiguate so much.

if ( (strlen($Type) > 0) && (strlen($Brand) > 0  ) && (strlen($Size) > 0  ) && (strlen($Price) > 0 ) )

can just be

if ( strlen($Type) > 0 && strlen($Brand) > 0 && strlen($Size) > 0 && strlen($Price) > 0 )

and you need to escape your parenthesis

...

$sql= "select * from PRODUCTS where Type="$Type" and Brand="$Brand" and Size="$Size" order by ProductID");
...

This statement (as well as others like it) is not quite correct. Foremost, delete the close paren ')' at the end of the line. Next, you are concatenating strings, which usually requires the concatenation (.) operator as in:

$sql= "select * from PRODUCTS where Type=" . $Type . " and Brand=" . $Brand . " and Size=" . $Size . " order by ProductID";

But it may then generate an SQL error.

This statement would be better written as:

$sql= "select * from PRODUCTS where Type='$Type' and Brand='$Brand' and Size='$Size' order by ProductID";

or

$sql= "select * from PRODUCTS where Type='" . $Type . "' and Brand='" . $Brand . "' and Size='" . $Size . "' order by ProductID";

The former requires less typing and is probably clearer.

MySQL prefers values in queries to be in single quotes.

Next, on line 65,

$result=mysql_query("$sql");

the quotes around $sql are not needed. But they, like your explicit groupings in your if statements, won't hurt anything.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.