gpt4 book ai didi

php - 显示更新值时,$_GET 返回未定义索引错误,但在正常重定向时 $_GET 方法给出正确的值

转载 作者:行者123 更新时间:2023-11-29 18:09:59 29 4
gpt4 key购买 nike

这个问题可能看起来很相似,但请理解我的问题。在我的更新页面中,我对 $_GET 方法感到困惑。在我的第一页中,我提供了一个像这样编辑表格的链接

index.php

<?php
include_once("db.php");

$result1 = mysqli_query($connect, "SELECT * FROM mrinsert WHERE userid='{$_SESSION['user_id']}'");
?>
<?php

while($res = mysqli_fetch_array($result1)) {
echo "<tr>";
echo "<td>".$res['bugta']."</td>";
echo "<td>".$res['releaseta']."</td>";
echo "<td>".$res['ccota']."</td>";
echo "<td><a href=\"mredit.php?mrinsertid=$res[mrinsertid]\">Edit</a> | <a href=\"mrdelete.php?mrinsertid=$res[mrinsertid]\" onClick=\"return confirm('Are you sure you want to delete?')\">Delete</a></td>";
}
?>

我的 mredit.php 页面使用 mrinsertid 显示现有值。但是当尝试更新值时,它会在这个地方给出错误:

<?php
//getting id from url


$mrinsertid = $_GET['mrinsertid']; //ERROR Undefined index

//selecting data associated with this particular id
$result = mysqli_query($connect, "SELECT * FROM mrinsert WHERE mrinsertid=$mrinsertid"); //WARNING in this line

while($res = mysqli_fetch_array($result))
{
$releaseta=$res['releaseta'];
$keyta=$res['keyta'];
$programleadsta=$res['programleadsta'];
$ccota=$res['ccota'];
$nextmilestonesta=$res['nextmilestonesta'];
$bugta=$res['bugta'];
$risksta=$res['risksta'];
$summaryta=$res['summaryta'];

?>

我的整个mredit.php:

<?php
// including the database connection file
include_once("db.php");

if(isset($_POST['update']))
{
$mrinsertid = mysqli_real_escape_string($connect,$_POST['mrinsertid']);
$releaseta= mysqli_real_escape_string($connect,$_POST['releaseta']);
$keyta= mysqli_real_escape_string($connect,$_POST['keyta']);
$programleadsta= mysqli_real_escape_string($connect,$_POST['programleadsta']);
$ccota= mysqli_real_escape_string($connect,$_POST['ccota']);
$nextmilestonesta= mysqli_real_escape_string($connect,$_POST['nextmilestonesta']);
$bugta= mysqli_real_escape_string($connect,$_POST['bugta']);
$risksta= mysqli_real_escape_string($connect,$_POST['risksta']);
$summaryta= mysqli_real_escape_string($connect,$_POST['summaryta']);







// checking empty fields
if(empty($releaseta) || empty($keyta) || empty($programleadsta)||empty($ccota) || empty($nextmilestonesta) || empty($bugta)|| empty($riskta) || empty($summaryta)) {
if(empty($releaseta)) {
echo "<font color='red'>release field is empty.</font><br/>";
}

if(empty($keyta)) {
echo "<font color='red'>Akey field is empty.</font><br/>";
}

if(empty($programleadsta)) {
echo "<font color='red'>program field is empty.</font><br/>";
}
if(empty($ccota)) {
echo "<font color='red'>cco field is empty.</font><br/>";
}

if(empty($nextmilestonesta)) {
echo "<font color='red'>nextmilestone field is empty.</font><br/>";
}

if(empty($bugta)) {
echo "<font color='red'>bug field is empty.</font><br/>";
}
if(empty($risksta)) {
echo "<font color='red'>risk field is empty.</font><br/>";
}

if(empty($summaryta)) {
echo "<font color='red'>summary field is empty.</font><br/>";
}
} else {
//updating the table
$result = mysqli_query($connect, "UPDATE mrinsert SET releaseta='$releaseta',keyta='$keyta',programleadsta='$programleadsta',ccota='$ccota',nextmilestonesta='$nextmilestonesta',bugta='$bugta',risksta='$risksta',summaryta='$summaryta' WHERE mrinsertid='$mrinsertid'");

//redirectig to the display page. In our case, it is index.php
header("Location: index.php");
}
}

?>
<?php
//getting id from url


$mrinsertid = $_GET['mrinsertid'];

//selecting data associated with this particular id
$result = mysqli_query($connect, "SELECT * FROM mrinsert WHERE mrinsertid=$mrinsertid");

while($res = mysqli_fetch_array($result))
{
$releaseta=$res['releaseta'];
$keyta=$res['keyta'];
$programleadsta=$res['programleadsta'];
$ccota=$res['ccota'];
$nextmilestonesta=$res['nextmilestonesta'];
$bugta=$res['bugta'];
$risksta=$res['risksta'];
$summaryta=$res['summaryta'];

?>

<html>
<head>
<title>Edit Data</title>
</head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.wrap {
position:relative;
width:50px;
}
.wrap button {
border:5px solid;
position:absolute;
top:50px;
border-color:black;
border-radius: 50%;
margin-left:20px;
display:block;
height: 50px;
width: 50px;
background-color:green;

}
</style>
<body>
<a href="index.php">Home</a>
<br/>

<form name="form1" method="post" action="mredit.php">

<input type="text" name="mrinsertid" value=<?php echo $_GET['mrinsertid'];?> >
<input type="submit" name="update" value="update">

<div id="MRtableDIV">
<table border="2">
<tr style="background-color:#80bfff">
<th style="width:8%"><center>Release</center></th>
<th style="width:5%"><center>Status</center></th>
<th style="width:6%"><center>Key</center></th>
<th style="width:15%"><center>Program Leads</center></th>
<th style="width:6%"><center>CCO Dates</center></th>
<th style="width:6%"><center>Next Milestones</center></th>
<th style="width:10%"><center>Bug Projection</center></th>
<th style="width:14%"><center>Risks</center></th>
<th style="width:20%"><center>Summary</center></th>
<tr>
<tr>
<tr>
<td><textarea name="releaseta" id="ReleaseTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff""><?php echo $res['releaseta'];?></textarea></td>
<td>
<div class="wrap">
<button id="button1" value = "button" style= "color:white" onclick="setColor('button1', '#101010')";></button>
</div>
<textarea name="" id="StatusTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff"></textarea>
</td>
<td><textarea name="keyta" id="KeyTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff"><?php echo $res['keyta'];?></textarea></td>
<td><textarea name="programleadsta" id="ProgramLeadsTA" style="width:100%;height:200px;;resize:none;background-color:#e6f2ff"><?php echo $res['programleadsta'];?></textarea></td>
<td><textarea name="ccota" id="CCOTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff"><?php echo $res['ccota'];?></textarea></td>
<td><textarea name="nextmilestonesta" id="NextMilestonesTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff"><?php echo $res['nextmilestonesta'];?></textarea></td>
<td><textarea name="bugta" id="BugTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff"><?php echo $res['bugta'];?></textarea></td>
<td><textarea name="risksta" id="RisksTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff"><?php echo $res['risksta'];?></textarea></td>
<td><textarea name="summaryta" id="SummaryTA" style="width:100%;height:200px;resize:none;background-color:#e6f2ff"><?php echo $res['summaryta'];?></textarea></td>
</tr>
</tr>
</table>
</div>
</form>
</body>
</html>
<?php
}
?>

最佳答案

试试这个

我只是删除了 { } 并直接添加了 ".$_SESSION['user_id']; 并将查询存储在名为 的变量中$结果1

$result1 = "SELECT * FROM mrinsert WHERE user_id=".$_SESSION['user_id'];
$result = mysqli_query($conn, $result1);

if (mysqli_num_rows($result) > 0) {
// output data of each row
while($res = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>".$res['bugta']."</td>";
echo "<td>".$res['releaseta']."</td>";
echo "<td>".$res['ccota']."</td>";
echo "<td><a href='mredit.php?mrinsertid=".$res['mrinsertid']."'>Edit</a></td>";
}
}
else {
echo "0 results";
}
mysqli_close($conn);

mredit.php

echo $mrinsertid = $_GET['mrinsertid']; 

关于php - 显示更新值时,$_GET 返回未定义索引错误,但在正常重定向时 $_GET 方法给出正确的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47484894/

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