我完全被我的代码困住了。PHP - 脚本不从URL获得id值
<?php
$id = $_GET['kid'];
if (isset($_POST['mainit'])) {
if(!empty($_POST['new_kateg'])){
$jaunakategorija = $_POST['new_kateg'];
$kmst = $conn->prepare('UPDATE kategorijas SET kat_vards=:katvards WHERE kat_id=:katid');
$kmst->bindParam(':katvards', $jaunakategorija);
$kmst->bindParam(':katid', $id);
$kmst->execute();
if($kmst->execute()){
header('Location: new_kateg.php');
} else {
$message = '<p class="red">Kļūda </p>';
}
} else {
$message = '<p class="red">Lauks nedrīkst būt tukšs! </p>';
}
}
?>
<form action="kateg_edit.php" method="POST">
<p>Ievadiet jaunās kategorijas nosaukumu</p>
<?php echo $id; ?>
<input type="text" name="new_kateg" placeholder="Ievadiet nosaukumu">
<input type="submit" name="mainit" value="Mainīt!">
</form>
这是我从数据库更新记录的代码。
我的URL是:localhost /....../ kateg_edit.php? kid = 2
当我回显$ id它说它是2.代码做它的工作,但记录没有改变。
如果我硬编码$ id ='2';
代码作品和ID为2的记录已更改。
我卡住了为什么它不改变记录,当我从URL获得相同的数字!
这是以前的页面里是按钮labot(编辑)
<?php
$query = $conn->prepare("SELECT * FROM kategorijas");
$query->execute();
$result = $query;
echo
"<table class='table-fill'>
<tr>
<th>ID</th>
<th>Kategorijas nosaukums</th>
<th style='text-align:center;'>Darbība</th>"
;
foreach($result as $row)
{
echo "<tr>";
echo "<td>" . $row['kat_id'] . "</td>";
echo "<td>" . $row['kat_vards'] . "</td>";
echo '<td style="text-align:center;"><a href="kateg_edit.php?kid=' . $row['kat_id'] . '">Labot</a>
<a href="new_kateg.php?deleteid=' . $row['kat_id'] . '">Dzēst</a></td>';
}
echo "</tr>";
echo "</table>";
?>
感谢您的帮助......
Wheres html for you get query which which two tie together? – Option
好吧,让你得到'$ _GET ['kid']'正确。$ _POST ['mainit']'和'$ _POST ['new_kateg']'set && not empty? –
要访问编辑页面的页面不相关,您需要显示可以编辑条目的代码/表单 – jeroen