gpt4 book ai didi

php - 尝试将函数的结果保存在 php 上

转载 作者:行者123 更新时间:2023-11-29 13:14:44 26 4
gpt4 key购买 nike

我有一个这样的功能。在我的程序中为优惠券制作随机代码的功能:

<?php
function rcode() {
//rancangan kode
$fak = mysql_query("select * from master where master.npm = '$_SESSION[username]'"); // dapat dari inputan
while ($fakk = mysql_fetch_array($fak)) {
$_SESSION['id_fak'] = $fakk['id_fak'];
};
$fakultas = "0" . $_SESSION['id_fak'];
$jur = mysql_query("select id from master where master.npm = '$_SESSION[username]'"); // dapat dari inputan
while ($jurr = mysql_fetch_array($jur)) {
$_SESSION['id'] = $jurr['id'];
};
$jurusan = $_SESSION['id'];

$result = mysql_query("
SHOW TABLE STATUS LIKE 'konfirmasi'
");
$data = mysql_fetch_assoc($result);
$next_increment = $data['Auto_increment'];
//$next_increment = 99999;

if ($next_increment < 10) {
$voucher = $fakultas . "00" . $jurusan . "0" . "0" . $next_increment;
echo $voucher;
} else if ($next_increment < 100 and $next_increment >= 10) {
$voucher = $fakultas . "00" . $jurusan . "0" . $next_increment;
echo $voucher;
} else if ($next_increment < 1000 and $next_increment >= 100) {
$voucher = $fakultas . "00" . $jurusan . $next_increment;
echo $voucher;
} else if ($next_increment < 10000 and $next_increment >= 1000) {
$depan = substr($next_increment, 0, 1);
$sisa = substr($next_increment, 1, 3);
$voucher = $fakultas . "0" . $depan . $jurusan . $sisa;
echo $voucher;
} else if ($next_increment >= 10000) {
$puluhribuan = substr($next_increment, 0, 1);
$ribuan = substr($next_increment, 1, 1);
$sisa = substr($next_increment, 2, 3);

$voucher = $fakultas . $puluhribuan . $ribuan . $jurusan . $sisa;
echo $voucher;
}
//echo rand();
}

?>

所以,我尝试插入我的sql,但它应该可以工作。这是代码:

<?php
rcode();
?>
<?php
if (isset($_POST['konfirmasi'])) {
$voucherr = rcode();
mysql_query("insert into konfirmasi(voucher) values('$voucherr')");
} else {
?>
<form action="tampilbarcode.php" action="POST">
<input type="hidden" name="username" value="<?php echo $_SESSION['username']; ?>" />
<input type="submit" name="konfirmasi" value="CETAK PDF">
</form>
<?php
}
?>

请帮助我,这是我的论文计划。

最佳答案

您应该在 rcode() 函数末尾执行 return $voucher 而不是 echo $voucher

关于php - 尝试将函数的结果保存在 php 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21619844/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com