#
<form name="Item Search" method="post" action="search1.php">
#
Item Search:<br>
#
<label>
#
<input name="swords" type="text" size="30" maxlength="30">

</label>

<br>

<label>

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

</label>

<a href="logout.php">Logout</a>

</form>

<?php

if(isset($_POST['submit'])||isset($_POST['swords'])||isset($_GET['swords'])){

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

{

$search=$_POST['swords'];

}else

{

$search=$_GET['swords'];

}
$newurl = "search.php?swords=";

$searchwords = addslashes(htmlspecialchars($_POST['swords']));

{

$words = explode(' ',$searchwords);

$totalwords = count($words);

$i = 0;

$searchstring = "";

while ($i != $totalwords){

if ($i != 0 and $i != $wordcount){

$searchstring .= " and ";;

}

$searchstring .= "b_name LIKE '%$words[$i]%'";

$searchstring1 .= "b_author LIKE '%$words[$i]%'";

$i = $i + 1;

when i search "the" it's show all the "the" first words but if i type "the giver"
it dont show anything how can i search in the database if i have space above is my code i use can anybody modify it?

Recommended Answers

All 2 Replies

Your use of like clause is perfect as this is the way to search the values in such case. I think the problem is cause by the following line
$searchwords = addslashes(htmlspecialchars($_POST));

Remove addslashes and htmlspecialchars and then try

Your use of like clause is perfect as this is the way to search the values in such case. I think the problem is cause by the following line
$searchwords = addslashes(htmlspecialchars($_POST));

Remove addslashes and htmlspecialchars and then try

I know the problem the closing tags is the problem but by the way thank you for your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.