我的文件名是contacts.php;我希望如果按下选择按钮,则调用选择函数。但它显示错误。我编写了以下代码:
//contacts.php
<?php
//1.CREATE CONNECTION
$connection=mysql_connect("localhost","root","human");
if(!$connection)
{
die("DataBase Connection Failed: ".mysql_error());
}
//2.SELECT DATABASE
$db_select=mysql_select_db("vikas",$connection);
if(!$db_select)
{
die("DataBase Selection Failed: ".mysql_error());
}
if(isset($_REQUEST['select']))
{
select();
}
//select function
function select()
{
echo '<div id="show" style="background-color:#DDDDDD;">';
$result=mysql_query("select * from contacts", $connection);
if(!$result)
{
die("DataBase Query Failed: ".mysql_error());
}
echo <<<END
<table name=contact>
<tr><th>ID</th>
<th>NAME</th>
<th>NUMBER</th></tr>
END;
while($row=mysql_fetch_array($result))
{
echo '<tr><td>'.$row["number"].'</td><td>'.$row["name"].'</td></tr>';
}
echo '</div>';
}
//end of select
?>
<html>
<body>
<form action="contacts.php">
ENTER ID:<br>
<input type="text" name="id"/><br>
ENTER NAME(20 chars):<br>
<input type="text" name="name"/><br>
ENTER NUMBER(10 digits):<br>
<input type="text" name="number"/><br>
<input type="submit" name="select" value="select"/>
</form>
</body>
</html>
但它显示错误未定义的 var 连接。请帮助这是错误“未定义的变量:C:\wamp\www\site2sms-call\contacts.php 中的连接”