我正在尝试提交一个表单,并且我一直收到这行代码的错误,我已经以另一种形式使用并且工作得非常好。请指导我做什么,因为我是PHP的新手,我将永远感激不尽!
$quantity=$_POST['r_quantity'];
$name=$_POST['r_firstname'];
$sname=$_POST['r_lastname'];
$tel=$_POST['r_telno'];
$email=$_POST['r_email'];
$party=$_GET['eventName'];
if (!$name or !$sname or !$tel or !$email or !$quantity)
{
echo "<p>Your form is incomplete ";
echo "<br>Please fill in details ";
include("footlayout.html");
}
else
{
$SQL="insert into Bookings(customerFName, customerSName, customerTelNo, customerEmail, tickets) values ('".$name."','".$sname."','".$tel."','".$email."','".$quantity."')";
$exeSQL=mysql_query($SQL);
echo"Thank you for booking ";
}
$ASQL="select Quantity from PARTY where Name='$party'";
$exeASQL=mysql_query($SQL) or die (mysql_error());
$array=mysql_fetch_array($exeASQL);
$quantity=$array['r_quantity'];
if ($ticket>$quantity)
{
echo"Sorry There are only:" .$quantity;
include("footlayout.html");
exit;
}
echo"Thank you for booking tickets to";
echo $party;
编辑:完成更改后,两条消息都显示“感谢您预订”和“抱歉只有:”同时,变量中的两个值都不会显示。我怎么能解决这个问题?我会把另一个'或'放进去吗?
答案 0 :(得分:1)
替换:
{$ASQL="select Quantity from PARTY where Name='$party'";
$exeASQL=mysql_query($SQL) or die (mysql_error());
$array=mysql_fetch_array($exeASQL);
$quantity=$array['r_quantity'];
使用
$ASQL="select Quantity from PARTY where Name='$party'";
$exeASQL=mysql_query($SQL) or die (mysql_error());
$array=mysql_fetch_array($exeASQL);
$quantity=$array['r_quantity'];
(删除“$ ASQL”之前的大括号)
答案 1 :(得分:1)
使用此:
if (!$name || !$sname || !$tel || !$email || !$quantity)
{
echo "<p>Your form is incomplete ";
echo "<br>Please fill in details ";
include("footlayout.html");
}
else
{
$SQL="insert into EventBookings(customerFName, customerSName, customerTelNo, customerEmail, tickets) values ('".$name."','".$sname."','".$tel."','".$email."','".$quantity."')";
$exeSQL=mysql_query($SQL);
echo"Thank you for booking ";
}
{$ASQL="select Quantity from PARTY where Name='$party'";
$exeASQL=mysql_query($SQL) or die (mysql_error());
$array=mysql_fetch_array($exeASQL);
$quantity=$array['r_quantity'];
if ($ticket>$quantity)
{
echo "Sorry There are only:".$quantity;
include("footlayout.html");
exit;
}
echo"Thank you for booking tickets to";
echo $party;
你的错误:
echo"Sorry There are only:" $quantity;
需要使用:
echo "Sorry There are only:" . $quantity;
也许你需要使用&#34; ||&#34;而不是&#34;或&#34;。
答案 2 :(得分:1)
请更改代码
echo"Sorry There are only:". $quantity;