当我删除这些值时,它运行良好。当我搜索时,它运行良好。仅当我在编辑后尝试保存数据时才会收到错误消息。
我也尝试使用
if(!isset($_GET['edit']))
{
echo '<form action="" method="post">';
echo '<input type="text" name=criteria>';
echo '<input type="submit" value="search" name="submit">';
echo '</form>';
}
但它没有用。
我收到的错误是(!) SCREAM:错误抑制忽略(!)注意:未定义的索引:第 13 行 C:\wamp\www\test\search.php 中的条件。
整个代码是
<html>
<head>
</head>
<body>
<?php
$page='search.php';
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("list") or die (mysql_error());
if(empty($_POST) === false)
{
$data=$_POST['criteria'];
if (empty($data) === true)
{
echo 'Please enter some text!!<br/>';
}
else
{
$get=mysql_query("SELECT SRNO, fname, lname, phone, email, address, comments from names where fname='" . mysql_real_escape_string($data) . "'");
if (mysql_num_rows($get)==0)
{
echo 'There are no search results!!';
}
else
{
echo '<table border=0 cellspacing=25 cellpadding=1>';
echo'<tr><th>Sr. No</th><th>First Name</th><th>Last Name</th><th>Phone No</th><th>E-mail</th><th>Address</th><th>Comments!!</th><th>Modify</th><th>Delete!</th></tr>';
while($get_row=mysql_fetch_assoc($get))
{
echo '<tr><td>'.$get_row['SRNO'].'</td><td>'.$get_row['fname'].'</td><td>'.$get_row['lname'].'</td><td>'.$get_row['phone'].'</td><td>'.$get_row['email'].'</td><td>'.$get_row['address'].'</td><td>'.$get_row['comments'].'</td><td><a href="search.php?edit='.$get_row['SRNO'].'">Edit</a></td><td><a href="search.php?delete='.$get_row['SRNO'].'">Delete</a></td></tr>';
}
echo '</table>';
}
}
/*
if(mysql_num_rows($getf) == 0)
{
$getel=mysql_query('SELECT SRNO, fname, lname, phone, email, address, comments from names where lname='.$_GET['$data']));
}*/
}
if(isset($_GET['delete']))
{
mysql_query('DELETE from names where SRNO='.mysql_real_escape_string((int)$_GET['delete']));
}
if(isset($_GET['edit']))
{
$getedit=mysql_query('SELECT SRNO, fname, lname, phone, email, address, comments from names where SRNO='.mysql_real_escape_string((int)$_GET['edit']));
echo '<table border=0>';
while ($get_row=mysql_fetch_assoc($getedit))
{
echo '<form method="POST" action="">';
echo '<tr><td>Sr.No:</td><td><input type="text" value='.$get_row['SRNO'].' name="SRNO" readonly="readonly"></td></tr>';
echo '<tr><td>First Name:</td><td><input type="text" value='.$get_row['fname'].' name="fname"></td></tr>';
echo '<tr><td>Last Name:</td><td><input type="text" value='.$get_row['lname'].' name="lname"></td></tr>';
echo '<tr><td>Phone No:</td><td><input type="text" value='.$get_row['phone'].' name="phone"></td></tr>';
echo '<tr><td>E-mail address:</td><td><input type="text" value='.$get_row['email'].' name="email"</td></tr>';
echo '<tr><td>Address:</td><td><textarea name="address" rows=4>'.$get_row['address'].'</textarea></td></tr>';
echo '<tr><td>Comments:</td><td><textarea name="comments" rows=4>'.$get_row['comments'].'</textarea></td></tr>';
echo '<tr><td><input type="submit" name="submit" value="save"></td><td><a href="search.php">Cancel</a></td></tr>';
echo '</form>';
}
echo '</table>';
}
if(!isset($_GET['edit']))
{
echo '<form action="" method="post">';
echo '<input type="text" name=criteria>';
echo '<input type="submit" value="search" name="submit">';
echo '</form>';
}
?>
</body>
</html>
有两种形式,只有一种
if(empty($_POST) === false)
如何在 if 语句中添加条件来过滤每个条件?请帮忙