if statement /mysql help please

Reply

Join Date: May 2009
Posts: 1
Reputation: juanki09 is an unknown quantity at this point 
Solved Threads: 0
juanki09 juanki09 is offline Offline
Newbie Poster

if statement /mysql help please

 
0
  #1
May 23rd, 2009
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

  1. <?php
  2. $dbHost = "UVCvoldb.db.3892101.hostedresource.com";
  3. $dbUser = "UVCvoldb";
  4. $dbPass = "UVCvol2008";
  5. $dbDatabase = "UVCvoldb";
  6.  
  7. $Type=($_GET['Type']);
  8. $Brand=($_GET['Brand']);
  9. $Size=($_GET['Size']);
  10. $Price=($_GET['Price']);
  11. $Model=($_GET['Model']);
  12.  
  13. $db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
  14.  
  15.  
  16.  
  17. mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
  18.  
  19. if ( (strlen($Type) > 0) && (strlen($Brand) > 0 ) && (strlen($Size) > 0 ) && (strlen($Price) > 0 ) )
  20. {
  21. $sql= "select * from PRODUCTS where Type="$Type" and Brand="$Brand" and Size="$Size" and Price="$Price" order by ProductID");
  22. }
  23.  
  24. elseif ( (strlen($Type) > 0) && (strlen($Brand) > 0 ) && (strlen($Size) > 0 ) )
  25. {
  26. $sql= "select * from PRODUCTS where Type="$Type" and Brand="$Brand" and Size="$Size" order by ProductID");
  27. }
  28.  
  29. elseif ( (strlen($Type) > 0) && (strlen($Brand) > 0 ) )
  30. {
  31. $sql= "select * from PRODUCTS where Type="$Type" and Brand="$Brand" order by ProductID");
  32. }
  33.  
  34. elseif ( (strlen($Type) > 0) )
  35. {
  36. $sql= "select * from PRODUCTS where Type="$Type" order by ProductID");
  37. }
  38.  
  39. elseif ( (strlen($Brand) > 0) )
  40. {
  41. $sql= "select * from PRODUCTS where Brand="$Brand" order by ProductID");
  42. }
  43.  
  44. elseif ( (strlen($Size) > 0) )
  45. {
  46. $sql= "select * from PRODUCTS where Size="$Size" order by ProductID ");
  47. }
  48.  
  49. elseif ( (strlen($Price) > 0) )
  50. {
  51. $sql= "select * from PRODUCTS where Price="$Price" order by ProductID");
  52. }
  53.  
  54. elseif ( (strlen($Model) > 0) )
  55. {
  56. $sql= "select * from PRODUCTS where Model="$Model" order by ProductID");
  57. }
  58.  
  59. else
  60. {
  61. $sql= "select * from PRODUCTS";
  62. }
  63.  
  64.  
  65. $result=mysql_query("$sql");
  66.  
  67. //filter table start
  68. echo <<<END
  69.  
  70. <form action="products.php?Category=TV" meathod="GET">
  71.  
  72. <input type="hidden" value="TV" Name="Category">
  73.  
  74. <table width="969" border="1">
  75.  
  76. <tr>
  77.  
  78. <td>Type</td>
  79.  
  80. <td><select name="Type"><option selected="selected" value="">None</option>
  81.  
  82. <option Value="Flat Screen Plasma">Flat Screen Plasma</option>
  83.  
  84. <option Value="Flat Screen LCD"> Flat Screen LCD</option>
  85.  
  86. </select>
  87.  
  88. </td>
  89.  
  90. <td>Brand</td>
  91.  
  92. <td><select name="Brand"><option selected="selected" value="">None</option>
  93.  
  94. <option Value="Sony">Sony</option>
  95.  
  96. <option Value="LG"> LG</option>
  97.  
  98. </select>
  99.  
  100. </td>
  101.  
  102. <td>Size</td>
  103.  
  104. <td><select name="Size"><option selected="selected" value="">None</option>
  105.  
  106. <option Value="26">26</option>
  107.  
  108. <option Value="34"> 34</option>
  109.  
  110. </select>
  111.  
  112. </td>
  113.  
  114. <td>Price</td>
  115.  
  116. <td><select name="Price"><option selected="selected" value="">None</option>
  117.  
  118. <option Value="$200-$300">$200-$300</option>
  119.  
  120. <option Value="$300-$500"> $300-$500</option>
  121.  
  122. <option Value="$500-$1500"> $500-$1500</option>
  123.  
  124. </select>
  125.  
  126. </td>
  127.  
  128. <td>Model</td>
  129.  
  130. <td><input type="text" Name="Model"></td>
  131.  
  132. <td><input type="Submit" name="submit" value="submit"><input type="reset" name="reset" value="Clear"></td>
  133.  
  134. </tr>
  135.  
  136. </table>
  137.  
  138. </form>
  139.  
  140. END;
  141.  
  142. // filter table end
  143.  
  144.  
  145.  
  146. while($row = mysql_fetch_array( $result )) {
  147.  
  148. // displaying products
  149.  
  150. $Image=$row['Image'];
  151.  
  152. $Name=$row['Name'];
  153.  
  154. $ModelNum =$row['Model#'];
  155.  
  156. $ProductID=$row['ProductID'];
  157.  
  158. echo "<table width=969>";
  159.  
  160. echo "<tr><td rowspan=4 width=201>";
  161.  
  162. echo "<form target=_blank action=viewproduct.php method=post><input type=hidden value=$ProductID name=ProductID />";
  163.  
  164. echo "<input type=image src=$Image width=201 heigth=144> </form>";
  165.  
  166. echo "</td><td colspan=2>$Name</td></tr>";
  167.  
  168. echo "<tr><td>Model#:$ModelNum</td><td>Product ID: $ProductID</td></tr>";
  169.  
  170. 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>";
  171.  
  172. echo "</table>";
  173.  
  174. echo "<hr width=969>";
  175.  
  176. }
  177.  
  178.  
  179.  
  180. ?>
  181.  
  182. </div>
  183.  
  184. </center>
Last edited by juanki09; May 23rd, 2009 at 8:13 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,435
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 232
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is online now Online
Code Monkey

Re: if statement /mysql help please

 
0
  #2
May 23rd, 2009
You're missing an ending parenthesis on almost all of those conditions. You don't need to disambiguate so much.
  1. if ( (strlen($Type) > 0) && (strlen($Brand) > 0 ) && (strlen($Size) > 0 ) && (strlen($Price) > 0 ) )
can just be
  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 74
Reputation: sacarias40 is an unknown quantity at this point 
Solved Threads: 0
sacarias40's Avatar
sacarias40 sacarias40 is offline Offline
Junior Poster in Training

Re: if statement /mysql help please

 
0
  #3
May 23rd, 2009
and you need to escape your parenthesis
no dejes para maƱana lo que puedes hacer hoy
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: if statement /mysql help please

 
0
  #4
May 24th, 2009
Originally Posted by juanki09 View Post
...
  1. $sql= "select * from PRODUCTS where Type="$Type" and Brand="$Brand" and Size="$Size" order by ProductID");
  2. ...
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:
  1. $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:
  1. $sql= "select * from PRODUCTS where Type='$Type' and Brand='$Brand' and Size='$Size' order by ProductID";
or
  1. $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,
  1. $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.
Last edited by Fest3er; May 24th, 2009 at 12:40 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 399 | Replies: 3
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC