未定义的索引:第9行的C:\ wamp \ www alph \ search.php中的初始值...

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:

  1. Form element names not matching up with the POST variables that you're trying to access. Ex: Your field is called name but you're trying to access the POST variable names.
  2. A user accessing the page directly, instead of accessing it via a form.