please some one help me,i have created this code for searching from database but the problem is i am getting an output without even searching,i am no php expert,so please guys help me.

<form method="post"  action="<?php echo $_SERVER['PHP_SELF'] ?>" onSubmit="return validateThis(this)"> <!-- Sending Search Keyword to "search_handler.php" -->
						<p>
							<label for="name" id="lname">Search Here:</label>
							<input type="text" class="text" name="tag" id="tag" onfocus="input_focus('tag');" onblur="input_blur('tag');" size="50" />
						</p>
	<input type="submit" class="submit" name="send_contact" value="Send" />
						
					</form>

<?php
$tag = @$_POST['tag'];
$con = mysql_connect("localhost","root","");
	
	if (!$con)
	{
		die('Could not connect: ' . mysql_error());
	}
	mysql_select_db("root", $con);
	
	$result =mysql_query("Select * FROM `superbnexus`.`products` WHERE `prname`LIKE '%".$tag."%'");

//echo $tag;
  


if($row = mysql_fetch_array($result))
{
    echo "<b>Name: </b>".$row[0]."<br>";
    echo "<b>Product Details: </b>".$row[3]."<br>";
    echo "<b>Product Price: </b>".$row[4]."<br>";
    echo "<em>To Buy this Product you have to Register. To Register go to <i>Customer Menu > Product List</i></em>";
}
else
{
    echo "<strong>The Product you are Searching is Not Available right now!</strong>";
}
mysql_close($con);
?>

Hi

In the text box you have mention

onfocus="input_focus('tag');" onblur="input_blur('tag');"

try to remove and check

you can wrap you search code (right before $tag and after mysql_close() in an if statement like:

// this will only run the php code if the submit button was pressed on your page.
if (isset($_POST['submit'])) {
   $tag...
   // rest of your code.
    mysql_close($con);
}
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.