将页面 ID 存储在 mysql 中


Storing the page id In mysql

我有这个php代码。

<?php
      if (isset($_POST['name'], $_POST['post'])) {
             $cast = $_POST['cast'];
             $name = $_POST['name'];
             $email = $_POST['email'];
             $post = nl2br ($_POST['post']);
             $ipaddress = $_POST['ipaddress'];
if (empty($name) or empty($post)) {
             $error = 'All Fields Are Required!';
}else{
$query = $pdo->prepare('INSERT INTO comments (cast, name, email, post, ipaddress) VALUES(?, ?, ?, ?, ?)');
     $query->bindValue(1, $cast);
     $query->bindValue(2, $name);
     $query->bindValue(3, $email);
     $query->bindValue(4, $post);
     $query->bindValue(5, $ipaddress);
     $query->execute();
?>

而这种形式。

<?php if (isset($error)) { ?>
     <small style="color:#aa0000;"><?php echo $error; ?></small><br /><br />
<?php } ?>
<form action="episode.php?id=<?php echo $data['cast_id']; ?>" method="post" autocomplete="off" enctype="multipart/form-data">
<input type="text" name="name" placeholder="Name" /> / <input type="text" name="email" placeholder="Email" /><small style="color:#aa0000;">*</small><br /><br />
<textarea rows="10" cols="50" name="post" placeholder="Comment"></textarea><br /><br />
<input type="submit" value="Add Comment" />
<br /><br />
<small style="color:#aa0000;">* <b>Email will not be displayed publicly</b></small><br />
</form>

每个页面的 url 都显示以下内容:example.php?id=1,每个投射有一个单独的 id。

如何让我的表单添加 url 中的 id 以显示在上面的投射字段中?

请帮忙。

谢谢。

只需使用 $_GET['id'] 代替您的$data即可。

<form action="episode.php?id=<?php echo $_GET['id']; ?>"

您可以添加以下输入:

<input type="hidden" name="idpage" value="<?php echo $_GET['id']?>">