这是我的程序代码:
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$host = "localhost";
$user_name = "usr";
$pwd = "pwd";
$database_name = "my2"; //assuming you created this
mysql_connect($host, $user_name, $pwd)or die(mysql_error());
mysql_select_db($database_name)or die(mysql_error());
$datee = $_POST['datee'];
$time = $_POST['time'];
$destination = $_POST['destination'];
$days = $_POST['days'];
$cab = $_POST['cab'];
$route = $_POST['route'];
$full_name = $_POST['full_name'];
$address = $_POST['address'];
$mobile_number = $_POST['mobile_number'];
$pickup_location = $_POST['pickup_location'];
$query2 = "SELECT `order_number` FROM `count` WHERE 1";
$countQuery = mysql_query($query2)or die(mysql_error());
while($row = mysql_fetch_array($countQuery))
{
$order_number = $row["order_number"];
}
$query3 = "UPDATE `count` SET `order_number` = '".$order_number."'+ 1 WHERE 1";
mysql_query($query3)or die(mysql_error());
$query1="INSERT INTO booking VALUES ('".$datee."','".$time."','".$destination."','".$days."','".$cab."','".$full_name."','".$ad dress."','".$mobile_number."','".$pickup_location."','".$route."','".$order_number."')";
mysql_query($query1)or die(mysql_error());
?>
<html>
<body>
<div style="border:1px solid black;background-color:#FAFA23;width:600px;height:100px;">
<table>
<tr>
<td>
<?php
echo "Your order number is :".$order_number;
?>
</td>
</tr>
<tr align="center">
<td>Thank you for booking, We will contact you soon ! </td>
</tr>
</table>
</body>
</html>
执行此程序时,每次都会添加一行额外的行。
请告诉我这段代码有什么问题?
此外,当我想将列的值增加1时,它会增加2 ..see- order_number=order_number+1;
答案 0 :(得分:0)
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$host = "localhost";
$user_name = "usr";
$pwd = "pwd";
$database_name = "db"; //assuming you created this
mysql_connect($host, $user_name, $pwd)or die(mysql_error());
mysql_select_db($database_name)or die(mysql_error());
$datee = $_POST['datee'];
$time = $_POST['time'];
$destination = $_POST['destination'];
$days = $_POST['days'];
$cab = $_POST['cab'];
$route = $_POST['route'];
$full_name = $_POST['full_name'];
$address = $_POST['address'];
$mobile_number = $_POST['mobile_number'];
$pickup_location = $_POST['pickup_location'];
$query2 = "SELECT order_number FROM `count` WHERE 1";
$countQuery = mysql_query($query2)or die(mysql_error());
while($row = mysql_fetch_array($countQuery))
{
$variable = $row["order_number"];
}
$query3 = "UPDATE `count` SET `order_number` = ''".$order_number."'+ 1 WHERE 1";
mysql_query($query3)or die(mysql_error());
$query1="INSERT INTO booking VALUES ('".$datee."','".$time."','".$destination."','".$days."','".$cab."','".$full_name."','".$address."','".$mobile_number."','".$pickup_location."','".$route."','".$variable."')";
mysql_query($query1)or die(mysql_error());
?>
我已经在这里更新了你的问题代码,试试看,它们看起来很有用。
不要忘记创建$order_number
变量。