我正在尝试在数据库中插入一些东西,但是当我使用该脚本时,它会导致脚本错误的结束。
无论我订购什么订单,都无法解决它。
代码:
<?PHP
include('inc/database/db_connect.php'); //includes db settings
function sernum()
{
$template = 'X9XX-XX99-99XX-99X9-XXXX';
$k = strlen($template);
$sernum = '';
for ($i=0; $i<$k; $i++) {
switch($template[$i]) {
case 'X': $sernum .= chr(rand(65, 90)); break;
case '9': $sernum .= rand(0,9); break;
case '-': $sernum .= '-'; break;
}
return $sernum;
mysqli_query($db_connect,"INSERT INTO AlphaKeys (`AlphaKey`) VALUES ('$sernum');
mysqli_close($db_connect);
}
}
}
echo '<prev>';
for ($i=0; $i < 20; $i++) echo sernum(), '<br/>';
echo '</pre>';
?>
和db_connect.php
<?PHP
$connect_error = "Sorry, we're experiencing downtime, please try again.";
$db_connect = mysqli_connect("localhost","********","B&5I)0U%a-B}","********") or die($connect_error);
?>
我想弄清楚,我不能......
答案 0 :(得分:0)
纠正这一行
mysqli_query($db_connect,"INSERT INTO AlphaKeys (`AlphaKey`) VALUES ('$sernum');
到
mysqli_query($db_connect,"INSERT INTO AlphaKeys (`AlphaKey`) VALUES ('$sernum')");