dimanche 29 mars 2015

I Get This Notice: `Undefined index: searchterm` when i Search any Word

I'm sure my php code is fine. But when i use it in between html codes i cant receive the search elemet.



$search = mysql_real_escape_string(trim($_POST['searchterm']));


it fetches all records of my table.



<div id="spaces-main" class="pt-perspective">
<section class="page-section Portfolio-page page-section-57">
<div class="large-7 columns p-l-0">
<h2>
Portfolio
</h2>
</div>

<div class="row portfolio-page">
<div class="hide" id="project-info">
<div id="content">
<i class="fa-times fa back"></i>
<div class="row">
<div class="large-11 columns">
<h2 class="project-title">Super Design</h2>
</div>
<div class="large-6 columns">
<div class="project-images">
<div class="item-list">
<ul class="">
<li>
<a href="#">
<img width="500" height="380" alt="13tndZF" class="attachment-project-thumb" src="assets/images/12.jpg">
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="large-6 columns project-content">
<?php
//The Problem Is Here!
$search = mysql_real_escape_string(trim($_POST['searchterm']));


$hostname='localhost';
$username='root';
$password='';

try {
$dbh = new PDO("mysql:host=$hostname;dbname=search",$username,$password);
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$dbh->exec("SET CHARACTER SET utf8"); // return all sql requests as UTF-8

$sql = "SELECT * FROM a WHERE Name LIKE '%$search%' LIMIT 2";
$stmt = $dbh->query($sql);
foreach ($stmt as $row)
{
echo " Name : ".$row["Name"] ."<br/> Persian : ". $row["Persian"] ."<br/> Hindi :".$row["Hindi"]."<br/>";
}


$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}



?>

</div>
</div>
</div>
</div>


Could you please tell me what's wrong?


Aucun commentaire:

Enregistrer un commentaire