我传递值,以便我可以修改数据库的内容。
当我正确传递文本数据流和更新时。但对于textarea数据不会流动。 我传递的代码是:
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 rows=4>'.$get_row['address'].'</textarea></td></tr>';
echo '<tr><td>Comments:</td><td><textarea rows=4>'.$get_row['comments'].'</textarea></td></tr>';
echo '<tr><td><input type="submit" name="submit" value="save"></td><td></td></tr>';
echo '</form>';
}
echo '</table>';
我传递的代码是:
if (empty($_POST) === false)
{
$fname= $_POST['fname'];
$lname= $_POST['lname'];
$srno= $_POST['SRNO'];
$address=$_POST['address'];
$comments=$_POST['comments'];
$email=$_POST['email'];
$phone=$_POST['phone'];
echo 'Hello'.$address;
mysql_query('update names set fname="'.$fname.'", lname="'.$lname.'", address="'.$address.'", comments="'.$comments.'", email="'.$email.'", phone="'.$phone.'" where SRNO="'.$srno.'"');
header('Location:'.$page);
}
完整的代码是:
<!DOCTYPE html>
<html>
<head>
<title>List of users</title>
</head>
<body>
<?php
$page='index.php';
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("list") or die (mysql_error());
if (empty($_POST) === false)
{
$fname= $_POST['fname'];
$lname= $_POST['lname'];
$srno= $_POST['SRNO'];
$address=$_POST['address'];
$comments=$_POST['comments'];
$email=$_POST['email'];
$phone=$_POST['phone'];
echo 'Hello'.$address;
mysql_query('update names set fname="'.$fname.'", lname="'.$lname.'", address="'.$address.'", comments="'.$comments.'", email="'.$email.'", phone="'.$phone.'" where SRNO="'.$srno.'"');
header('Location:'.$page);
}
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 rows=4>'.$get_row['address'].'</textarea></td></tr>';
echo '<tr><td>Comments:</td><td><textarea rows=4>'.$get_row['comments'].'</textarea></td></tr>';
echo '<tr><td><input type="submit" name="submit" value="save"></td><td></td></tr>';
echo '</form>';
}
echo '</table>';
}
$get=mysql_query('SELECT SRNO, fname, lname, email, phone, address, comments from names ORDER BY SRNO ASC');
if (mysql_num_rows($get)==0)
{
echo 'There are no entries';
}
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></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="index.php?edit='.$get_row['SRNO'].'">Edit</a></td></tr>';
}
echo '</table>';
}
?>
</body>
</html>
答案 0 :(得分:1)
为您的textarea代码添加名称标签;
echo '<tr><td>Address:</td><td><textarea rows=4 name="address">'.$get_row['address'].'</textarea></td></tr>';
答案 1 :(得分:0)
您的textarea没有name属性。它应该是:
echo '<tr><td>Address:</td><td><textarea name="address" rows=4>'.$get_row['address'].'</textarea></td></tr>';
echo '<tr><td >Comments:</td><td><textarea rows=4 name="comments">'.$get_row['comments'].'</textarea></td></tr>';
希望这有帮助