dougaimian1143 2015-05-05 03:34
浏览 40

生成qrcode后PHP脚本停止运行

Hello so basically I have this working code that generates a qr code image.

<?php
if (isset($_POST['btn_submit'])) {
    include('phpqrcode/qrlib.php');
    require '../db/dbc.php';
    try {
        $characters           = 'abcdefghijklmnopqrstuvwxyz0123456789';
        $strlength            = 5;
        $string               = '';
        for ($i = 0; $i < $strlength; $i++) {
            $string .= $characters[rand(0, strlen($characters) - 1)];
        }

        $query       = "INSERT INTO tbl_residents (fname, mname, lname, address, uname, pword, acct_status, department, contact_no, date_reg) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        $stmt        = $dbc->prepare($query);
        $pword       = sha1($string);
        $now         = date('m/d/Y');
        $acct_status = "active";
        $stmt->bindParam(1, $_POST['txt_fn']);
        $stmt->bindParam(2, $_POST['txt_mn']);
        $stmt->bindParam(3, $_POST['txt_ln']);
        $stmt->bindParam(4, $_POST['txt_address']);
        $stmt->bindParam(5, $_POST['txt_un']);
        $stmt->bindParam(6, $pword);
        $stmt->bindParam(7, $acct_status);
        $stmt->bindParam(8, $_POST['txt_dept']);
        $stmt->bindParam(9, $_POST['txt_cnum']);
        $stmt->bindParam(10, $now);
        $stmt->execute();
    }
    catch (PDOException $e) {
        echo "Error: " . $e->getMessage();
    }
}

$uncode = intval($string, 36);
// outputs image directly into browser, as PNG stream 
QRcode::png("login-link.php?code=$uncode");


?>

If I wanted to add details such as name, department and contact number under the php closing tag, it won't show up. But the code still runs and still generates a qr code image.

Below the php end tag I added this but it doesn't work.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ID Creation</title>
</head>
<body>
   Name: <?= $_POST['txt_fn']. " " . $_POST['txt_mn'] . " " . $_POST['txt_fn']; ?>  <br />
   Department: <?= $_POST['txt_dept']; ?>  <br />
   Contact No.: <?= $_POST['txt_cnum']; ?>
</body>
</html>

If you remove the qr code generation line below, it works.

$uncode = intval($string, 36);
// outputs image directly into browser, as PNG stream 
QRcode::png("login-link.php?code=$uncode");

So basically, the line QRcode::png("login-link.php?code=$uncode"); stops the code from executing. It doesn't read any lines below it. Any thoughts? Thank you

  • 写回答

1条回答 默认 最新

  • doomm4711 2015-05-05 04:11
    关注

    Hello so I've managed to fix my own problem by adding parameter to the qrcode generator and it looks like this

    From

    QRcode::png("login-link.php?code=$uncode");
    

    To

    QRcode::png("login-link.php?code=$uncode", "qr_images/$string.png");
    

    And in my html code it looks like this:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>ID Creation</title>
    </head>
    <body>
       <img src="qr_images/<?= $string.".png"; ?>">
       Name: <?= $_POST['txt_fn']. " " . $_POST['txt_mn'] . " " . $_POST['txt_fn']; ?>  <br />
       Department: <?= $_POST['txt_dept']; ?>  <br />
       Contact No.: <?= $_POST['txt_cnum']; ?>
    </body>
    </html>
    

    Thanks for your time looking at my problem.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab