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 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程