数据将加载到窗口,并且ahref编辑能够单击以将变量“id”传递到弹出窗口,其中代码位于同一页面上。
while($row = mysql_fetch_array($result))
{
$id=$row['file_id'];
echo '<span class=right><a href="#edit_form?id='.$id.'">[edit]</a>
}
/* This is the pop up form code */
<a href="#x" class="overlay" id="edit_form"></a>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("isiti");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_GET["id"]))
{
$id =$_GET["id"];
}
$result = mysql_query("SELECT * FROM publication where file_id='$id'");
$row1 = mysql_fetch_array($result);
$title=$row1['title'];
$author=$row1['author'];
$year=$row1['year'];
$abstract=$row1['abstract'];
if(!empty($_SESSION['username']))
{
echo'<div class="popup">';
echo'<form method="POST" action="public_edit.php" enctype="multipart/form-data">';
echo'<div>';
echo'<label for="citation">Title</label>'; echo'<input style="width:100%;" type="text" name="title" id="title" value="'.$title.'">';
echo'</div>';
echo'<div>';
echo'<label for="citation">Author</label>';
echo'<input style="width:100%;" type="text" name="author" id="author" value="'.$author.'">';
echo'</div>';
echo'<div>';
echo'<label for="citation">Year</label>';
echo'<input style="width:100%;" type="year" name="year" id="year" value="'.$year.'">';
echo'</div>';
echo'<div>';
echo'<label for="abstract">Abstract</label>';
echo'<textarea name="abstract" id="abstract" size="5000">'.$abstract.'</textarea>';
echo'</div>';
echo'<p>Rechoose your file here</p>';
echo'<input type="hidden" name="MAX_FILE_SIZE" value="2000000">';
echo'<input name="userfile" type="file" id="userfile"> ';
echo'<br/> ';
echo'<input name="submit" type="submit" value="Upload" style="width: 150px">';
echo'<a class="close" href="#close"></a>';
echo'</form>';
echo'</div>';
}
我遇到的问题是它没有传递正确的ID。无论我点击什么链接,它都会显示第一个id的数据。
感谢您的帮助。
答案 0 :(得分:0)
更新:现在这是一个文件:
<?php
if(!empty($_SESSION['username']))
{
$con=mysqli_connect("localhost","root","","isiti");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(empty($_GET['id'])){ /* IF EMPTY GET ID, FETCH LIST OF AVAILABLE FOR EDIT DATA */
$result=mysqli_query($con,"SELECT * FROM publication");
while($row = mysqli_fetch_array($result))
{
$id=$row['file_id'];
echo '<span class=right><a href="edit.php?id=$id">[edit]</a>'; /* CHANGED THE HREF */
}
} /* END IF EMPTY GET ID */
else { /* ELSE IF THERE'S AN ID TO GET */
$id=$_GET['id']; /* GET ID */
$result = mysqli_query($con,"SELECT * FROM publication where file_id='$id'");
while($row1 = mysqli_fetch_array($result)){
$title=$row1['title'];
$author=$row1['author'];
$year=$row1['year'];
$abstract=$row1['abstract'];
}
echo'<div class="popup">';
echo'<form method="POST" action="public_edit.php" enctype="multipart/form-data">';
echo'<div>';
echo'<label for="citation">Title</label>'; echo'<input style="width:100%;" type="text" name="title" id="title" value="'.$title.'">';
echo'</div>';
echo'<div>';
echo'<label for="citation">Author</label>';
echo'<input style="width:100%;" type="text" name="author" id="author" value="'.$author.'">';
echo'</div>';
echo'<div>';
echo'<label for="citation">Year</label>';
echo'<input style="width:100%;" type="year" name="year" id="year" value="'.$year.'">';
echo'</div>';
echo'<div>';
echo'<label for="abstract">Abstract</label>';
echo'<textarea name="abstract" id="abstract" size="5000">'.$abstract.'</textarea>';
echo'</div>';
echo'<p>Rechoose your file here</p>';
echo'<input type="hidden" name="MAX_FILE_SIZE" value="2000000">';
echo'<input name="userfile" type="file" id="userfile"> ';
echo'<br/> ';
echo'<input name="submit" type="submit" value="Upload" style="width: 150px">';
echo'<a class="close" href="#close"></a>';
echo'</form>';
echo'</div>';
} /* END OF ELSE */
} /* END OF IF NOT EMPTY SESSION */
你的代码与MySQL和MySQLi混合在一起。我改变了,只把它变成了MySQLi。