生成qrcode后,PHP脚本停止运行

时间:2015-05-05 03:34:30

标签: php qr-code

你好基本上我有这个工作代码生成一个qr代码图像。

<?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");


?>

如果我想在php结束标记下添加名称,部门和联系电话等详细信息,则不会显示。但代码仍然运行并仍然生成一个qr代码图像。

在php结束标记下面我添加了这个,但它没有用。

<!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>

如果删除下面的qr代码生成行,则可以正常工作。

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

基本上,行QRcode :: png(&#34; login-link.php?code = $ uncode&#34;);停止执行代码。它没有读取它下面的任何行。有什么想法吗?谢谢

1 个答案:

答案 0 :(得分:0)

您好我已经设法通过向qrcode生成器添加参数来解决我自己的问题,它看起来像这样

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

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

在我的html代码中,它看起来像这样:

<!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>

感谢您抽出时间查看我的问题。