我有一个提交给firstpage.php的表单,此页面包含将所有表单值插入数据库并检查重复条目的代码,如果该条目是重复条目,请使用以下php代码显示重复条目

 $checkstudentID = mysqli_query
($dbcon, "SELECT studentid from courses WHERE studentid = '$studentid'");
if(mysqli_num_rows($checkstudentID) > 0){
if ($stmt = mysqli_prepare($dbcon, "SELECT ckb from courses WHERE studentid = ?")) {

    mysqli_stmt_bind_param($stmt,"s",$studentid);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_bind_result($stmt, $ckb);
    mysqli_stmt_fetch($stmt);

        printf("<br /><center><h1>Your Student ID is</h1> <h2>%s.</h2><h1> Subjects Registered :  %s\n </h1>", $studentid, $ckb );

    mysqli_stmt_close($stmt);
}

mysqli_close($dbcon);


        die("  <p> The Student ID  <strong>$studentid </strong>already exists. <a href=\"update.html\">Update</a></p>");


页面update.html包含提交给update.php的更新表单

如何将单个获取的行变量(已注册主题/ $ ckb)传递给update.html?

到目前为止,我尝试了以下方法:

在firstpage.php,我开始了一个会议

session_start();
$_SESSION['subjects'] = '$ckb';


并在update.html>重命名为update2.php,并在页面顶部添加以下内容

 <?php
session_start();
echo $_SESSION['sujects'];
?>


在输入字段中,value="<?php echo $ckb;?>"

我想念什么?

请注意,我要传递的变量是与在firstpage.php文件中检查的学生ID相关的注册主题,这意味着:

printf("<br /><center><h1>Your Student ID is</h1> <h2>%s.</h2><h1> Subjects Registered :  **%s**\n </h1>", $studentid, $ckb );


但它要么完全错误,要么我只是传递了错误的变量

最佳答案

删除引号:

$_SESSION['subjects'] = '$ckb';


因此它将是:

$_SESSION['subjects'] = $ckb;


并将第二个文件更新为:

 <?php
session_start();
$ckb = $_SESSION['subjects'];
?>
....
<input type='text' value="<?php echo $ckb;?>" />


注意:同样,您在第二个文件中写了sujects,在我的代码示例中还可以。

08-03 20:26
查看更多