Jump to content

[SOLVED] PHP Search Script, Having trouble.


fLaVV

Recommended Posts

Hello, I am tryin to make a PHP script that searches a template database for eathier the name, serial or style. The problem I am having is when i enter the Name for a test, it doesn't bring up any result. I have information entered into the database, but when i type in Google in the name field, it doesnt find the row in the database that contains Google.com. Here is the code.

 

 

<?

$cnx = mysql_connect('localhost', 'flaw_root', '****') or die ("Could not connect");

mysql_select_db('flaw',  $cnx) or die (mysql_error());

?>

 

 

<form action="search.php" method="POST">

<table width="725" border="1" cellpadding="0" cellspacing="0">

  <tr>

    <td width="222">Name:</td>

    <td width="228">Serial:</td>

    <td width="205">Style:</td>

    <td width="60"> </td>

  </tr>

  <tr>

    <td><input type="text" name="name" id="name" /></td>

    <td>

      <input type="text" name="serial" id="serial" />

    </td>

    <td>

      <select name="style" id="style">

        <option selected="selected">--Select Style --</option>

        <option value="clean">Clean</option>

        <option value="dark">Dark</option>

        <option value="light">Light</option>

        <option value="futuristic">Futuristic</option>

        <option value="vector">Vector</option>

        <option value="retro">Retro</option>

    </select>

    </td>

    <td>

      <input type="hidden" name="search" value="true">

      <input type="submit" name="submit" id="submit" value="Search!" />

    </td>

  </tr>

</table>

</form>

 

 

<?

if($_POST['search'] == "true"){

$name = $_POST['name'];

$serial = $_POST['serial'];

$style = $_POST['style'];

 

$sql = "SELECT * FROM mytable WHERE name LIKE '% .$name. %' OR serial LIKE '$serial' OR style LIKE '$style' ORDER BY mytable_id DESC"; 

    $query = mysql_query($sql) or die(mysql_error()); 

    $row_sql = mysql_fetch_assoc($query); 

    $total = mysql_num_rows($query);

 

    if($total>0) {

  while ($row_sql = mysql_fetch_assoc($query)) {  //echo out the results 

    echo ''.$row_sql['name'].'<br />'.$row_sql['style'].''; 

    } 

} else {

echo "No results to display"; 

}

}

?> 

 

sorry to take your time.

Link to comment
Share on other sites

Looks to me like its just your dots(.) in the query. Try:

 

<?php
$sql = "SELECT * FROM mytable WHERE name LIKE '%$name%' OR serial LIKE '$serial' OR style LIKE '$style' ORDER BY mytable_id DESC";  
?>

 

And just as a by the by, try and post code inside [ code][ /code] tags with full php opening tags so we get syntax highlighting - it makes it so much easier to read :)

Link to comment
Share on other sites

Sorry, couldnt remember the sytax for the code, tried to edit post but cant find it :P...ill give that a try and see if it works. Thanks

 

 

I tried that and get the same results, saying there are no results found and yet i know there is something in the row on that table.

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.