PHP 请问 Notice: Undefined variable
Notice:Undefinedvariable:rsin/home/sujata/Public/guestbook4/edit.phponline44(48,52,56...
Notice: Undefined variable: rs in /home/sujata/Public/guestbook4/edit.php on line 44 (48,52,56)
请问问题出在哪里,先谢谢啦
<?php
define('DEBUG', ture);
if (DEBUG) {
ini_set("display_errors", 1);
error_reporting(E_ALL);
}
include "conn.php";
if (!empty($_GET['id'])) {
$sql = 'SELECT * FROM user where id = ' . $_GET['id'];
$query = mysql_query($sql);
$rs = mysql_fetch_array($query);
}
if (!empty($_POST['sub'])) {
$username = $_POST['username'];
$email = $_POST['email'];
$content = $_POST['content'];
$refer_url = $_POST['refer_url'];
$mysql = 'UPDATE user SET username = ' . $username . ', email = ' . $email . ', content = ' . $content . ', refer_url = ' . $refer_url;
if (mysql_query($mysql)) {
echo "修改成功!";
header("refresh:5;url = 'admin.php'");
} else {
echo "修改失败";
}
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html" charset="utf8" />
<title>编辑</title>
</head>
<body>
<table>
<form method="post" action="edit2.php">
<tr>
<td>用户名:</td>
<td><input type="text" name="username" value="<?php echo $rs['username'];?>" /></td>
</tr>
<tr>
<td>邮箱:</td>
<td><input type="text" name="email" value="<?php echo $rs['email'];?>" />请输入你的邮箱,方便我们及时取得联系</td>
</tr>
<tr>
<td>内容:</td>
<td><textarea name="content" cols="50" rows="5"><?php echo $rs['content'];?></textarea></td>
</tr>
<tr>
<td>反馈网址:</td>
<td><input type="text" name="refer_url" value="<?php echo $rs['refer_url'];?>" /></td>
</tr>
<tr>
<td><input type="submit" name="sub" value="提交" /></td>
</tr>
</form>
</table>
</body>
</html> 展开
请问问题出在哪里,先谢谢啦
<?php
define('DEBUG', ture);
if (DEBUG) {
ini_set("display_errors", 1);
error_reporting(E_ALL);
}
include "conn.php";
if (!empty($_GET['id'])) {
$sql = 'SELECT * FROM user where id = ' . $_GET['id'];
$query = mysql_query($sql);
$rs = mysql_fetch_array($query);
}
if (!empty($_POST['sub'])) {
$username = $_POST['username'];
$email = $_POST['email'];
$content = $_POST['content'];
$refer_url = $_POST['refer_url'];
$mysql = 'UPDATE user SET username = ' . $username . ', email = ' . $email . ', content = ' . $content . ', refer_url = ' . $refer_url;
if (mysql_query($mysql)) {
echo "修改成功!";
header("refresh:5;url = 'admin.php'");
} else {
echo "修改失败";
}
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html" charset="utf8" />
<title>编辑</title>
</head>
<body>
<table>
<form method="post" action="edit2.php">
<tr>
<td>用户名:</td>
<td><input type="text" name="username" value="<?php echo $rs['username'];?>" /></td>
</tr>
<tr>
<td>邮箱:</td>
<td><input type="text" name="email" value="<?php echo $rs['email'];?>" />请输入你的邮箱,方便我们及时取得联系</td>
</tr>
<tr>
<td>内容:</td>
<td><textarea name="content" cols="50" rows="5"><?php echo $rs['content'];?></textarea></td>
</tr>
<tr>
<td>反馈网址:</td>
<td><input type="text" name="refer_url" value="<?php echo $rs['refer_url'];?>" /></td>
</tr>
<tr>
<td><input type="submit" name="sub" value="提交" /></td>
</tr>
</form>
</table>
</body>
</html> 展开
1个回答
展开全部
-_-|| 好长的代码,undefine variable意思就是没有定义变量,Notice只是提示而已,你这里的提示就是在第44行没有定义rs这个变量,当然PHP应该是属于动态语言,所以这里只是提示,想忽略的话可以用@,我是不晓得你的第44行在哪。。。
更多追问追答
追问
" />
您好,上面是第44行。
追答
你的rs的确没有定义过,如果你是想把数据库中的东西输出来,那要在数据库操作的代码中找到mysql_fetch_array函数,把找来的数据给rs
$rs = mysql_fetch_array($sql_query); //这是我常用的操作,$sql_query是SQL查询语句
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询