0

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>
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by takeshi
0

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?

Edited by amd_k8: n/a

0

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)){ ..

Edited by takeshi: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.