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

Link to comment
Share on other sites

I just want it to go through all the fields in the database, for both 'form' and 'colour'.  I am not sure what to put for this WHERE statement.  Could you maybe give me and example, in reference to a database?

 

Thanks for the quick reply!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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