| | |
if statement /mysql help please
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2009
Posts: 1
Reputation:
Solved Threads: 0
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
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 Syntax (Toggle Plain Text)
<?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>
Last edited by juanki09; May 23rd, 2009 at 8:13 pm.
You're missing an ending parenthesis on almost all of those conditions. You don't need to disambiguate so much.
can just be
php Syntax (Toggle Plain Text)
if ( (strlen($Type) > 0) && (strlen($Brand) > 0 ) && (strlen($Size) > 0 ) && (strlen($Price) > 0 ) )
php Syntax (Toggle Plain Text)
if ( strlen($Type) > 0 && strlen($Brand) > 0 && strlen($Size) > 0 && strlen($Price) > 0 )
Last edited by ShawnCplus; May 23rd, 2009 at 8:56 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
Join Date: Aug 2007
Posts: 165
Reputation:
Solved Threads: 18
•
•
•
•
...PHP Syntax (Toggle Plain Text)
$sql= "select * from PRODUCTS where Type="$Type" and Brand="$Brand" and Size="$Size" order by ProductID"); ...
PHP Syntax (Toggle Plain Text)
$sql= "select * from PRODUCTS where Type=" . $Type . " and Brand=" . $Brand . " and Size=" . $Size . " order by ProductID";
This statement would be better written as:
PHP Syntax (Toggle Plain Text)
$sql= "select * from PRODUCTS where Type='$Type' and Brand='$Brand' and Size='$Size' order by ProductID";
PHP Syntax (Toggle Plain Text)
$sql= "select * from PRODUCTS where Type='" . $Type . "' and Brand='" . $Brand . "' and Size='" . $Size . "' order by ProductID";
MySQL prefers values in queries to be in single quotes.
Next, on line 65,
PHP Syntax (Toggle Plain Text)
$result=mysql_query("$sql");
Last edited by Fest3er; May 24th, 2009 at 12:40 am.
![]() |
Similar Threads
- Supplied argument is not a valid MySQL result resource (MySQL)
- intersect in MySQL (MySQL)
- return result set in SPs (MySQL)
- how to use select statement of mysql in vb application (Visual Basic 4 / 5 / 6)
- Question about SELECT statement. (MySQL)
Other Threads in the PHP Forum
- Previous Thread: How to split text into pages?
- Next Thread: How to implement check availability in hotel reservation system
Views: 399 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code codingproblem cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select send server sessions sms soap source space speed sql static structure syntax system table tutorial up-to-date update updates upload url validation validator variable video web wordpress xml youtube






