0

Dear experties,
I want to display data from Mysql by keyword but my code doesn't work.
Maybe you have suggestion for this environment.
please...

2
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by ryantroop
0

Thanks for reply.. there are my codes

?php
include 'connection/db_connect.php';
?>

<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <p>
    <label for="key"></label>
    <input type="text" name="key" id="key">
    <input type="submit" name="Submit" id="Submit" value="Submit">
  </p>
  <table width="200">
    <tr>
      <td>id</td>
      <td>dept</td>
    </tr>
    <?php 
    if(isset($_POST["Submit"])){            
    $sql ="SELECT * FROM user WHEN name LIKE '{%key%}'";
    $result=mysql_query($sql);
        }
    while ($row=mysql_fetch_array($result)) {
    ?>
    <tr>
      <td><?php echo $row['empNo']; ?></td>
      <td><?php echo $row['name']; ?></td>
    </tr>
    <?php }?>
  </table>
  <p>&nbsp;</p>
</form>
0

the searching will act like DaniWeb search engine..
It will display result when the string entred contains in database field..
hurmm but my code doesn't work..

1
if(isset($_POST['key']{
$key = $_POST['key'];
$sql = "SELECT * FROM user WHEN name LIKE '{%$key%}'";
....

you probably dont even need the {} and you may want to escape $key before you pop it in your query.

Edited by ryantroop

0

i had tried it but still no result..
it doesn't work..

0

Sorry, not sure why that happened.. if you copy and pasted directly I missed two parentheses.

should be:

if(isset($_POST['key'])){
$key = $_POST['key'];
$sql = "SELECT * FROM user WHERE name like '%$key%';";
....
}
0

My God!!
Thank you so much~~~ it's worked!!
yesterday i had tried change the code many ways but didn't put the ; qoute...
Awesome...Thank you s much ryantroop!

This question has already been answered. 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.