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
https://forums.phpfreaks.com/topic/56102-solved-php-search-script-having-trouble/
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 :)

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.

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.