Below is my code for a search in php. I'm having a problem to run this program. so please help me?
<html>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("login");
$initial = mysql_real_escape_string($_POST['initial']);
$find_videos = mysql_query("SELECT * FROM `sigup` WHERE `initial` LIKE '%initial%'");
while($row = mysql_fetch_assoc($find_videos))
{
$initial = $row['initial'];
echo "$initial<br/ >";
}
?>
</body>
</html>
Your problem is on this line:
$initial = mysql_real_escape_string($_POST['initial']);
Basically, the issue is caused whenever the POST variable initial
does not exist. When the POST variable initial
does not exist, the index initial
will not exist in the $_POST array.
You should always check to see if a POST or GET variable exists before you attempt to use it. You can do this by using the function isset:
if(isset($_POST['initial'])){
//initial exists as a POST variable
} else{
//initial does not exist as a POST variable
}
Of course, you could also use this in ternary form:
$initial = isset($_POST['initial']) ? mysql_real_escape_string($_POST['initial']) : false;
if($initial !== false){
//Good to go
}
Some causes of POST variables not existing when you think they should:
name
but you're trying to access the POST variable names
.