错误提示如下:
注意:未定义的变量:last_id in 第87行的C:\ xampp \ htdocs \ CIS \ addSubscriber.php
以下是代码:
if(mysql_query("INSERT INTO subscribers(fName, mName, lName, suffix, globeNumber, emailAddress, contactNumber,
address, state, country, virtualNumber, agentCode, ipAddress, dateRegistration, dateStarted, dateExpired, time,
transaction_id, accountStatus, subscriptionStatus, status, remarks)
VALUES ('$fName' , '$mName', '$lName', '$sName', '$globe', '$emailAdd', '$contactNo', '$address', '$state', '$country',
'$virtualNum', '$cAgentCode', '$ipAddress', '$dateRegistration', '$dateStarted', '$dateExpired', '$time',
'$transaction', '$accStatus', '$subsStatus', '$status', '$remarks' )"))
{
$last_id = mysql_insert_id();
}
**//this is line 87**
$query = "INSERT INTO `transactions` (`transactionNumber`, `subscriptionStart`, `subscriptionEnd`, `subsStatus`, `cus_id`)
VALUES ('".$transaction."', , '".$dateStarted."', '".$dateExpired."', '".$subsStatus."', '".$last_id."');";
if($query_run = mysql_query($query)){
?>
<script> alert('<?php echo $last_id; ?>');
</script>
<?php
} else {
?>
<script>alert('Agent Code is not available!');</script>
<?php
}
}
echo mysql_error();
我在其他文件中尝试使用它,但它正常工作我无法找到错误的触发器。
与基本未定义变量错误不同:
答案 0 :(得分:1)
这个怎么样?
$query = mysql_query("INSERT INTO subscribers(fName, mName, lName, suffix, globeNumber, emailAddress, contactNumber,
address, state, country, virtualNumber, agentCode, ipAddress, dateRegistration, dateStarted, dateExpired, time,
transaction_id, accountStatus, subscriptionStatus, status, remarks)
VALUES ('$fName' , '$mName', '$lName', '$sName', '$globe', '$emailAdd', '$contactNo', '$address', '$state', '$country',
'$virtualNum', '$cAgentCode', '$ipAddress', '$dateRegistration', '$dateStarted', '$dateExpired', '$time',
'$transaction', '$accStatus', '$subsStatus', '$status', '$remarks' )");
if(!$query)
{
echo mysql_error();
}
else
{
$last_id = mysql_insert_id();
$query2 = mysql_query("INSERT INTO `transactions` (`transactionNumber`, `subscriptionStart`, `subscriptionEnd`, `subsStatus`, `cus_id`)
VALUES ('$transaction', '$dateStarted', '$dateExpired', '$subsStatus', '$last_id')");
if(!$query2)
{ ?>
<script>
alert('<?php echo $last_id; ?>');
</script>
<?php
}
else {
?>
<script>
alert('Agent Code is not available!');
</script>
<?php
}
}
MySQL
扩展名在PHP 5.5.0中已弃用,并已在PHP 7.0.0中删除。相反,应该使用MySQLi或PDO_MySQL扩展。小号
答案 1 :(得分:1)
尝试放
else { die(mysql_error()); }
找到错误。