Jump to content

[SOLVED] Retrieving Informaton from Database


skipskap

Recommended Posts

Hey all,

 

I'm new to the forums wahey!  I have ran into a problem and hopefully someone can let me know how to fix it.  Basically, I have a text field and a submit button, once the submit button is clicked I want it to search the database looking for the anything that matches what the user typed into the text field.  Here is what I have done so far...

 

<body>

 

<?php

 

if(isset($_POST['search']))

{

 

// connect to database files

 

include 'config.php';

include 'connect.php';

 

// variables

 

$search=$_POST["search"];

$query  = "SELECT name, colour FROM pink LIKE '%$search%'";

$result = mysql_query($query);

 

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{

    echo "Name :{$row['name']} <br>" .

        "Message : {$row['colour']} <br><br>";

}

 

 

//  close database

 

include 'close.php';

echo "Search Results";

 

}

 

else

 

{

?>

 

<form method="post">

 

<table width="500" border="2" cellspacing="0" cellpadding="0">

  <tr>

    <td colspan="2">Please fill out the form below:</td>

  </tr>

  <tr>

    <td>search:</td>

    <td>

 

<input name="search" type="text" />

 

</td>

  </tr>

  <tr>

    <td>Click >></td>

    <td>

 

<input name="submit" type="submit" id="submit" value="search">

 

</td>

  </tr>

</table>

 

</form>

 

<?php

}

?>

</body>

 

Any help with this would be much appreciated!

 

Thanks,

 

Jordan

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.