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

would need to see the code to see what you are trying to accomplish.

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>

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

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.

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

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%';";
....
}

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!

Youre welcome :)

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.