我试图在values标签中默认显示一些文本,我试图在form value中回显$row。但是,我注意到了未定义的变量。有没有人能弄清楚这个错误?
<?php
$id=$_GET['id'];
$qry=mysql_query('SELECT * FROM pages WHERE pageid="$id"', $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
while($row=mysql_fetch_array($qry))
{
$row=mysql_fetch_array($qry);
}
?>
<div class="block2">
<p><b>Update Article</b></p>
<form action="article_edited.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<p>Article Id :
<label for="image"></label>
<input type="text" name="pageid" id="pageid" value="<?php echo $row['pageid']?>" />
</p>
<label for="image"></label>
<p>Image Path:
<input type="text" name="imgpath" id="imgpath" value="<?php echo $row['imgpath'] ?>" />
</p>
<p>Contents :
<label for="cont"></label>
<textarea name="contents" id="contents" cols="50" rows="5" ><?php $row['text'] ?></textarea>
</p>
<p align="center">
<input type="submit" name="Submit" id="Submit" value="Submit" />
</p>
</form>更新#1:这是我遵循的教程:http://www.vdesignourweb.com/cmsphpsqlb/cms_editarticle.html
更新#2:这是my Table结构:

更新#3:我刚刚发现这个表没有索引。这会是问题所在吗?
发布于 2012-09-20 20:49:12
您只需在while循环中定义$row。它不是在while循环之外定义的。您需要将值存储在一个数组或其他东西中,以便在while循环结束后或在while循环期间执行!
$results = array();
while($row=mysql_fetch_array($qry)){
$results [] = $row;
}
foreach($results as $row){
echo $row['pageid'];
}发布于 2012-09-20 20:51:43
如果是单个记录,可以检查是否有从查询返回的记录,然后使用
$row=mysql_fetch_array($qry);
而不是
while($row=mysql_fetch_array($qry))
{
$row=mysql_fetch_array($qry);
}您还可以研究一下mysql_fetch_row。我建议你远离mysql_*,因为它太老了,已经过时了。
发布于 2012-09-20 20:52:43
修改while循环,如下所示:
$array=array();
while($row=mysql_fetch_array($qry))
{
$array[]=mysql_fetch_array($qry);
}然后,在你的文本区域中,让它说
<?php echo $row['text'] //you missed the echo statement ?>或者,您可以简单地使用<?= //what you want to echo here ?>而不是<?php echo //what you want to echo ?>
https://stackoverflow.com/questions/12512939
复制相似问题