gpt4 book ai didi

php将变量传递给弹出窗口,该窗口的代码在同一页面上

转载 作者:行者123 更新时间:2023-11-30 00:29:45 24 4
gpt4 key购买 nike

数据将加载到窗口,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">&nbsp;';
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 的数据。

谢谢你帮助我。

最佳答案

更新:现在这是一个文件:

<?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">&nbsp;';
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。

关于php将变量传递给弹出窗口,该窗口的代码在同一页面上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22600210/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com