fLaVV Posted June 18, 2007 Share Posted June 18, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56102-solved-php-search-script-having-trouble/ Share on other sites More sharing options...
GingerRobot Posted June 18, 2007 Share Posted June 18, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/56102-solved-php-search-script-having-trouble/#findComment-277099 Share on other sites More sharing options...
fLaVV Posted June 18, 2007 Author Share Posted June 18, 2007 Sorry, couldnt remember the sytax for the code, tried to edit post but cant find it ...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. Quote Link to comment https://forums.phpfreaks.com/topic/56102-solved-php-search-script-having-trouble/#findComment-277191 Share on other sites More sharing options...
gtk Posted June 19, 2007 Share Posted June 19, 2007 I think this Url will help you alot. http://www.zend.com/forums/index.php?t=msg&goto=10074 Quote Link to comment https://forums.phpfreaks.com/topic/56102-solved-php-search-script-having-trouble/#findComment-277383 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.