Guys,this code couldn't run very well..Is there anyone who will recode this?
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>

Well... seems that you lost a curly brace ({) and a semi-colon in your switch statement...
Next, where is your actually searched string? I mean

$term = mysql_real_escape_string((string)$_POST['term']);

Third, your SQL syntax is kinda wrong ... LIKE '%term% ..., I suppose it should be - ... LIKE '%$term%' P.S. I have a Ford, could anyone rebuild it to Corvette?

Well... seems that you lost a curly brace ({) and a semi-colon in your switch statement...
Next, where is your actually searched string? I mean

$term = mysql_real_escape_string((string)$_POST['term']);

Third, your SQL syntax is kinda wrong ... LIKE '%term% ..., I suppose it should be - ... LIKE '%$term%' P.S. I have a Ford, could anyone rebuild it to Corvette?

amd_k8,still an error occur in my code...the error was while ($row = mysql_fetch_array($sql)){ ..

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.