PHP读取数据库数据问题急急急@@!!!
代码如下,执行后文本框内显示未定义的变量,该如何改<?php$id=$_GET["d"];$conn=mysql_connect("localhost","root","...
代码如下,执行后 文本框内显示未定义的变量,该如何改
<?php
$id = $_GET["d"];
$conn = mysql_connect("localhost","root","");
mysql_select_db("news",$conn);
mysql_query("set names gbk");
$ContentEditSql = "SELECT contentTitle,classId,contentTime,contentInfo,contentId FROM newsContent WHERE ContentId = ".$id;
$ContentEditResult = mysql_query($ContentEditSql);
if($ContentEditResult){
$ContentEditRows = mysql_fetch_array($ContentEditResult);
$contentTitle=$ContentEditRows["contentTitle"];
$classId=$ContentEditRows["classId"];
$contentTime=$ContentEditRows["contentTime"];
$contentInfo=$ContentEditRows["contentInfo"];
}else{
echo "<script>alert('错误的数据');javascript:history.back(1)</script>";
}
mysql_close();
?>
<form method="post" action="newseditok.php">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="16%">新闻标题:</td>
<td width="80%"><input name="contentTitle" type="text" id="contentTitle" value="<?php echo $contentTitle?>" /></td>
<td width="4%"> </td>
</tr>
<tr>
<td>所属类型:</td>
<td><input name="classId" type="text" id="classId" value="<?php echo $classId?>" /></td>
<td> </td>
</tr>
<tr>
<td>发布时间:</td>
<td><input name="contentTime" type="text" id="contentTime" value="<?php echo $contentTime?>" /></td>
<td> </td>
</tr>
<tr>
<td>新闻内容:</td>
<td><textarea name="contentInfo" id="contentInfo"><?php echo $contentInfo?></textarea></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="提交" />
<input name="contentid" type="hidden" id="contentid" value="<?php echo $id?>" /></td>
<td> </td>
</tr>
</table>
</form>
这是我的另个页面,是没有问题的,两个页面的功能都是显示数据库的数据到文本框,然后修改数据后更新
<?php
$id = $_GET["d"];
$conn = mysql_connect("localhost","root","");
mysql_select_db("news",$conn);
mysql_query("set names gbk");
$classEditSql = "SELECT * FROM newsclass WHERE classid = ".$id;
$classEditResult = mysql_query($classEditSql);
if($classEditResult){
$classEditRews = mysql_fetch_array($classEditResult);
$className = $classEditRews[1];
}else{
echo "<script>alert('错误的数据');javascript:history.back(1)</script>";
}
mysql_close();
?>
<form method="post" action="classeditok.php">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="16%">分类名称:</td>
<td width="80%"><input name="classname" type="text" id="classname" value="<?php echo $className?>" /></td> 展开
<?php
$id = $_GET["d"];
$conn = mysql_connect("localhost","root","");
mysql_select_db("news",$conn);
mysql_query("set names gbk");
$ContentEditSql = "SELECT contentTitle,classId,contentTime,contentInfo,contentId FROM newsContent WHERE ContentId = ".$id;
$ContentEditResult = mysql_query($ContentEditSql);
if($ContentEditResult){
$ContentEditRows = mysql_fetch_array($ContentEditResult);
$contentTitle=$ContentEditRows["contentTitle"];
$classId=$ContentEditRows["classId"];
$contentTime=$ContentEditRows["contentTime"];
$contentInfo=$ContentEditRows["contentInfo"];
}else{
echo "<script>alert('错误的数据');javascript:history.back(1)</script>";
}
mysql_close();
?>
<form method="post" action="newseditok.php">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="16%">新闻标题:</td>
<td width="80%"><input name="contentTitle" type="text" id="contentTitle" value="<?php echo $contentTitle?>" /></td>
<td width="4%"> </td>
</tr>
<tr>
<td>所属类型:</td>
<td><input name="classId" type="text" id="classId" value="<?php echo $classId?>" /></td>
<td> </td>
</tr>
<tr>
<td>发布时间:</td>
<td><input name="contentTime" type="text" id="contentTime" value="<?php echo $contentTime?>" /></td>
<td> </td>
</tr>
<tr>
<td>新闻内容:</td>
<td><textarea name="contentInfo" id="contentInfo"><?php echo $contentInfo?></textarea></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="提交" />
<input name="contentid" type="hidden" id="contentid" value="<?php echo $id?>" /></td>
<td> </td>
</tr>
</table>
</form>
这是我的另个页面,是没有问题的,两个页面的功能都是显示数据库的数据到文本框,然后修改数据后更新
<?php
$id = $_GET["d"];
$conn = mysql_connect("localhost","root","");
mysql_select_db("news",$conn);
mysql_query("set names gbk");
$classEditSql = "SELECT * FROM newsclass WHERE classid = ".$id;
$classEditResult = mysql_query($classEditSql);
if($classEditResult){
$classEditRews = mysql_fetch_array($classEditResult);
$className = $classEditRews[1];
}else{
echo "<script>alert('错误的数据');javascript:history.back(1)</script>";
}
mysql_close();
?>
<form method="post" action="classeditok.php">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="16%">分类名称:</td>
<td width="80%"><input name="classname" type="text" id="classname" value="<?php echo $className?>" /></td> 展开
2个回答
展开全部
是这句:$ContentEditSql = "SELECT contentTitle,classId,contentTime,contentInfo,contentId FROM newsContent WHERE ContentId = ".$id;
当id为空时没有考虑到。
可以改为:$ContentEditSql = "SELECT contentTitle,classId,contentTime,contentInfo,contentId FROM newsContent WHERE ContentId = '$id'";
注意$id是在两个单引号内的。
当id为空时没有考虑到。
可以改为:$ContentEditSql = "SELECT contentTitle,classId,contentTime,contentInfo,contentId FROM newsContent WHERE ContentId = '$id'";
注意$id是在两个单引号内的。
展开全部
试下把 $id = $_GET["d"]; 改成这样
if (isset($_GET["d"])) {
$id = $_GET["d"];
}else{
$id = '';
}
if (isset($_GET["d"])) {
$id = $_GET["d"];
}else{
$id = '';
}
更多追问追答
追问
不好意思,前面没说清楚是4个文本框的变量提示出错
追答
if (isset($_GET["d"])) {
$id = $_GET["d"];
}else{
$id = '';
}
$contentTitle='';
$classId='';
$contentTime='';
$contentInfo='';
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询