Hi..this code is not working..the error was while ($row = mysql_fetch_array($sql) but i know it was correct query.. search.php

<?php
  
      mysql_connect ("localhost", "root") or die (mysql_error());

      mysql_select_db ("records");

      $criteria = (int)$_POST['criteria'];

      $sql = "SELECT * FROM students WHERE ";

      switch($criteria)

      case 1: $sql .= "course"; break

      case 2: $sql .= "surname"; break;

      case 3: $sql .= "department"; break;
 
      case 4: $sql .= "email"; break;

      case 5: $sql .= "studno"; break;

      }
 
      $sql .= " LIKE '%term%'";
 
      while ($row = mysql_fetch_array($sql)){

       
  
      echo '<br/> Surname: '.$row['lname'];

      echo '<br/> Course: '.$row['course'];

      echo '<br/> Student No: '.$row['studno'];

      echo '<br/> Department: '.$row['department'];
 
      echo '<br/> Email Address: '.$row['email'];
 
      }
 
      ?>

form.php

<div>
  
      <form method="post" id="newsletterform" action="search.php">
 
      <p><input type="text" name="term" id="s" /></p>

      <p><select name="criteria">

      <option value="1">course</option>

      <option value="2">surname</option>
      <option value="3">department</option>

       

      <option value="4">email address</option>
 
      <option value="5">student no</option>
  
      </select></p>

      <p><button class="Button" type="submit" name="search"></p>
 
      </form>
.
      </div>

Recommended Answers

All 19 Replies

Perhaps this will work...

<?php
  
      mysql_connect ("localhost", "root",'password') or die (mysql_error());

      mysql_select_db ("records");

      $criteria = (int)$_POST['criteria'];

      $sql = "SELECT * FROM students WHERE ";

      switch($criteria)

      case 1: $sql .= "course"; break;

      case 2: $sql .= "surname"; break;

      case 3: $sql .= "department"; break;
 
      case 4: $sql .= "email"; break;

      case 5: $sql .= "studno"; break;

      }
 
      $sql .= " LIKE '%term%'";
      $r=mysql_query($sql) or die(mysql_error());
      while ($row = mysql_fetch_assoc($r)){

       
  
      echo '<br/> Surname: '.$row['lname'];

      echo '<br/> Course: '.$row['course'];

      echo '<br/> Student No: '.$row['studno'];

      echo '<br/> Department: '.$row['department'];
 
      echo '<br/> Email Address: '.$row['email'];
 
      }
 
      ?>

you know what takeshi.... im so sick and tired of debugging your code... i had help you many times and even provided code in many of your threads but you didn't had even the effort to payback the guys that helped you. You dont mark you thread solved. You just come here and beg for answers which is very annoying that some solutions are simple and obvious. i think your so lazy that your just copy and paste the code without even understanding it. Were like baby spoon feeding you here. Grow up and do you assignments on your own. You wont learn anything if you dont put your effort on it. I hope i make sense to you.

How is that any worse than copying peoples answer in hopes of stealing the solved count?

you know what takeshi.... im so sick and tired of debugging your code... i had help you many times and even provided code in many of your threads but you didn't had even the effort to payback the guys that helped you. You dont mark you thread solved. You just come here and beg for answers which is very annoying that some solutions are simple and obvious. i think your so lazy that your just copy and paste the code without even understanding it. Were like baby spoon feeding you here. Grow up and do you assignments on your own. You wont learn anything if you dont put your effort on it. I hope i make sense to you.

One of the best ways of learning is by asking for help and as long as you learn from that help then next time they should be able to solve the same problem by themselves.

How is that any worse than copying peoples answer in hopes of stealing the solved count?

you really feel good about yourself huh? I repeat i dont copy answers from dumb answers its not worth it.... i know moderators will get me from this as they like pick on small guy. Ive been quite a while on daniweb and ive seen many times members are cursing other people but dont get refractions. As for you, trying hard to provoke me to emotional response... im not scared and i dont care about reputations or whatsoever.

you really feel good about yourself huh? I repeat i dont copy answers from dumb answers its not worth it.... i know moderators will get me from this as they like pick on small guy. Ive been quite a while on daniweb and ive seen many times members are cursing other people but dont get refractions. As for you, trying hard to provoke me to emotional response... im not scared and i dont care about reputations or whatsoever.

This isn't about making me "feel good"

The moderators here don't pick on the small guy.

You appear to be paranoid.

One of the best ways of learning is by asking for help and as long as you learn from that help then next time they should be able to solve the same problem by themselves.

yeah thats exactly my point.... takeshi is just jumping from one problem to another. he do not absorbed the knowledge we provide. no effort at his side at all. he doesn't learn from it. he always ask for help.

This isn't about making me "feel good"

The moderators here don't pick on the small guy.

You appear to be paranoid.

and your the jeolous guy? :D

This isn't about making me "feel good"

The moderators here don't pick on the small guy.

You appear to be paranoid.

and your the jealous guy? :D

and your the jealous guy? :D

I wanna say that im not lazy even since i've started posting in this forum..for your higher information, every single code or i mean syntax you've posted,i always try to search the meaning,the function of that code..i have a tutorial here PHP and Javascript.And if you didn't know,i learned..i've gained new knowledge in some of your code.Yeah i searched,but if i do not find any answer,i just post in this forum..and ask some help..and yeah,i copy the code here but not all the codes i've asked here were copy and paste..well, it's your opinion and view of point,but you can't see me while thinking,debugging all the codes..Ya,learning comes from asking,and when you ask,there's an explanation why..Just ask and you learn something new..im not a typical person that you know copy and paste the codes, i searched. study the all the PHP codes in w3schools,print it so that i have a hard copy here..tnx for your commented..

I guess they ( and I) would like you to mark tour multiple threads a "solved" if you learned from them! That gives credit to those who have helped you .
I find myself wondering if you ever got any of your projects working, as you jump from one thread to another without ever marking the previous posts as solved.
In fact, it would be better if you shared the final solution so that others may learn as well. That's what it is supposed to be about here, people helping EACH OTHER, not just people helping YOU.
This perception of your presence here is why you are getting flamed.

Also,it takes twice as much time to help you because your English writing is a bit difficult to decipher at times. No problem, we do our best to help you anyway.
All we ask is that you AT LEAST acknowledge the effort from time to time.

I wanna say that im not lazy even since i've started posting in this forum..for your higher information, every single code or i mean syntax you've posted,i always try to search the meaning,the function of that code..i have a tutorial here PHP and Javascript.And if you didn't know,i learned..i've gained new knowledge in some of your code.Yeah i searched,but if i do not find any answer,i just post in this forum..and ask some help..and yeah,i copy the code here but not all the codes i've asked here were copy and paste..well, it's your opinion and view of point,but you can't see me while thinking,debugging all the codes..Ya,learning comes from asking,and when you ask,there's an explanation why..Just ask and you learn something new..im not a typical person that you know copy and paste the codes, i searched. study the all the PHP codes in w3schools,print it so that i have a hard copy here..tnx for your commented..

i really hope it's true as we are taking our time and effort on helping you here. About your error in search, you said that there's an error. can you show us the error?. coz. i didn't find any wrong in the code.

i really hope it's true as we are taking our time and effort on helping you here. About your error in search, you said that there's an error. can you show us the error?. coz. i didn't find any wrong in the code.

well,it's up to you if you beleive it or not..and anyway,i know what im doing here and not just to copy and paste but to learn something new from you and from them..Anyway,you made mistake for me..you showed me a negative thinker but i know it's just you..And about with marking threads,i always forgot to marked the thread though i want but i always forgot..but tnx for reminding me that.

ragarding with the code edited,they forgot to put $ in syntax %$term% that's why it didn't work at all..but since i put $, it works,show all the records from my database. but the problem is when i select one of the option such as course and type from the textbox 'BSCS',all the records were displayed and not only the BSCS courses..based on what swarn23 posted here http://www.daniweb.com/forums/thread256672.html

Any effort by the op would discover mismatched braces
Screwem, do their own damn homework

have you really doin some effort? havnt you noticed you had no opening curly brace( { ) in your switch in criteria. line 11.

have you really doin some effort? havnt you noticed you had no opening curly brace( { ) in your switch in criteria. line 11.

Oh i haven't noticed that.! i only have '}'...sorry,.

Oh i haven't noticed that.! i only have '}'...sorry,.

why people get POed,
get a code highlighting editor, and debug your own stuff before you ask
'I tried this and found that and dunno what to do next'
will get more help than
'I know its right'
when everybody else can see it isnt

and your the jealous guy? :D

tnx so much!.. :) it works!

wow takeshi started marking posts solved! :-O

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.