User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 403,363 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,278 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 323 | Replies: 3 | Solved
Reply
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 170
Reputation: lordx78 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Help Loop not working

  #1  
Mar 6th, 2008
  1. <?php
  2.  
  3. // connect to database
  4. include("inc/connect.php");
  5.  
  6. // include auth and nav
  7. //include("inc/auth.php");
  8.  
  9. // begin content
  10. //include("inc/nav.php");
  11.  
  12. // close mysql connection
  13. //mysql_close();
  14.  
  15. // Check if the form has been submitted.
  16. if (isset($_POST['Submit'])) {
  17.  
  18. $brandC = $_POST['brandC'];
  19. $typeC = $_POST['typeC'];
  20. $styleC = $_POST['styleC'];
  21. $frameC = $_POST['frameC'];
  22. $groupSetC = $_POST['groupSetC'];
  23.  
  24. $errors = array(); // Initialize error array.
  25.  
  26. //If they did not enter a search term we give them an error
  27. if (($brandC == "") AND ($typeC == "") AND ($styleC == "All") AND ($frameC == "") AND ($groupSetC == ""))
  28. {
  29. $errors[] = 'You did not select anything.';
  30. }
  31.  
  32. //If user only enter Bicycle Brand
  33. elseif (($brandC!="") AND ($typeC=="") AND ($styleC== "All") AND ($frameC== "") AND ($groupSetC== ""))
  34. {
  35. $result = mysql_query("SELECT * FROM cycles WHERE brand='$brandC'");
  36. }
  37.  
  38. //If user only enter Bicycle Type
  39. elseif (($brandC="") AND ($typeC!=="") AND ($styleC== "All") AND ($frameC== "") AND ($groupSetC== ""))
  40. {
  41. $result = mysql_query("SELECT * FROM cycles WHERE type='$typeC'");
  42. }
  43.  
  44. //If user only enter Bicycle Frame
  45. elseif (($brandC="") AND ($typeC=="") AND ($styleC == "All") AND ($frameC!== "") AND ($groupSetC== ""))
  46. {
  47. $result = mysql_query("SELECT * FROM cycles WHERE frame='$frameC'");
  48. }
  49.  
  50. //If user only enter Bicycle GroupSet
  51. elseif (($brandC="") AND ($typeC=="") AND ($styleC== "All") AND ($frameC== "") AND ($groupSetC!== ""))
  52. {
  53. $result = mysql_query("SELECT * FROM cycles WHERE groupSet='$groupSetC'");
  54. }
  55.  
  56. if (empty($errors)) { // If everything's OK.
  57.  
  58. echo "<table border=1 style='color:blue'>";
  59. echo "<tr>" ;
  60. echo "<td align=center style='color:red'>CID</td>";
  61. echo "<td align=center style='color:green'>Brand</td>";
  62. echo "<td align=center style='color:red'>Type</td>";
  63. echo "<td align=center style='color:green'>Style</td>";
  64. echo "<td align=center style='color:red'>Model</td>";
  65. echo "<td align=center style='color:green'>Gear No</td>";
  66. echo "<td align=center style='color:red'>Frame</td>";
  67. echo "<td align=center style='color:green'>Group Set</td>";
  68. echo "<td align=center style='color:red'>Price</td>";
  69. echo "<td align=center style='color:green'>Release Date</td>";
  70. echo "</tr>";
  71.  
  72. while($row = mysql_fetch_array($result))
  73. {
  74. echo "<tr>" ;
  75. echo "<td align=center>".$row['cycleID'] ."</td>";
  76. echo "<td align=center>".$row['brand']."</td>";
  77. echo "<td align=center>".$row['type']."</td>";
  78. echo "<td align=center>".$row['style']."</td>";
  79. echo "<td align=center>".$row['model'] ."</td>";
  80. echo "<td align=center>".$row['gearNo']."</td>";
  81. echo "<td align=center>".$row['frame']."</td>";
  82. echo "<td align=center>".$row['groupSet']."</td>";
  83. echo "<td align=center>".$row['price']."</td>";
  84. echo "<td align=center>".$row['releaseDate']."</td>";
  85. echo "</tr>";
  86. }
  87. echo "</table>";
  88.  
  89. exit();
  90.  
  91. } // End of if (empty($errors)) IF.
  92.  
  93. mysql_close(); // Close the database connection.
  94.  
  95. } // End of the main Submit conditional.
  96.  
  97. if (!empty($errors)) { // Print any error messages.
  98. echo "<h1 style='font-family:Calibri; color:red; text-align:center'>Error!</h1>
  99. <p style='font-family:Calibri; color:#0066FF; text-align:center'>The following <span style='color:red'>error(s)</span> occurred:</p>";
  100. foreach ($errors as $msg) { // Print each error.
  101. echo " <h5 style='font-family:Calibri; color:orange; text-align:center'> - $msg</h5>\n";
  102. }
  103. //echo '</p><p>Please try again.</p>';
  104.  
  105. echo "<h4 style='font-family:Calibri; color:green; text-align:center'>Please try again....</h4>
  106.  
  107. <br>
  108. <p style='font-family:Calibri; color:#0066FF; text-align:center'>You will now be returned to the find Cycle page again. <span style='color:red'>Please follow the rules!</span></p>
  109.  
  110. <META HTTP-EQUIV=\"refresh\" content=\"3; URL=findlist.php\"> ";
  111. }
  112. // Create the form.
  113. ?>

Only the 1st and the 2nd condition working rest not working.

error msg:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\cycle\find.php on line 72.
"I might not be the BEST but I'm not like the REST!"
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2006
Posts: 66
Reputation: silviuks is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 11
silviuks silviuks is offline Offline
Junior Poster in Training

Re: Loop not working

  #2  
Mar 6th, 2008
use $result = mysql_query($sql) or die (mysql_error());

if you have an error in your query it won't be executed and this is why you get that message.
Reply With Quote  
Join Date: Nov 2007
Location: Arkansas
Posts: 369
Reputation: buddylee17 will become famous soon enough buddylee17 will become famous soon enough 
Rep Power: 2
Solved Threads: 70
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Whiz

Re: Loop not working

  #3  
Mar 6th, 2008
#
//If user only enter Bicycle Type
#
elseif (($brandC="") AND ($typeC!=="") AND ($styleC== "All") AND ($frameC== "") AND ($groupSetC== ""))
I do this occasionally. You are confusing the comparison operators. On line 39, where you have $brandC="", you're not comparing the string to empty, you're resetting the value to empty. If you want to check if empty, use $brandC =="". Also, $typeC !=="" should be $typeC !="". There are also similar problems on line 45 & 51.
Or better yet, use
  1. elseif(empty($brandC) && !empty($typeC) && empty($frameC) && empty($groupSetC))
I could be wrong, but, I believe it will parse a bit faster.
Reply With Quote  
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 170
Reputation: lordx78 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Re: Loop not working

  #4  
Mar 6th, 2008
solved, thanks.
"I might not be the BEST but I'm not like the REST!"
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 8:56 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC