我添加到此表单的数据未添加到WAMP数据库

时间:2018-06-24 18:50:55

标签: php html mysql mysqli

这是我使用的PHP代码。当我输入以下HTML表单时,它不显示任何错误消息,但数据未添加到WAMP表

<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
//$user_name = "root";
//$password = "";
//$database = "cs_project";
//$server = "localhost";
$con=mysqli_connect("localhost","root","","cs_project") or die("Can't connect to the server");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
mysqli_select_db($con,"cs_project") or die("Can't connect to database");

if(isset($_REQUEST['submit'])) {
$v_number=$_POST["v_number"];
$date=$_POST["date"];
$from=$_POST["from"];
$to=$_POST["to"];
$destination=$_POST["destination"];
$collectpoint=$_POST["collectpoint"];
$payment_method=$_POST["payment_method"];

mysqli_query($linkz,"SELECT * FROM order_table");
$result = mysqli_query($con,"INSERT INTO order_table(v_number,date,from,to,destination,collectpoint,payment_method) VALUES('$v_number','$date','$from','$to','$destination','$collectpoint','$payment_method')"); 
if (!$result) {
 die('Invalid query: ' . mysqli_error()); 
 } 
echo "Data added";
}
mysqli_close($con);
?>

这是我使用的HTML代码。 Pease可以帮助我:(我完全受够了。是否需要通过表单输入所有表列??或者这是我的WAMP服务器还是其他问题??

<html>
<head>
<title> Vehicle reservation </title>
<style type="text/css">
th,td{color:#993366; font-family:Candara; font-size:20px; padding:10px; text-align:left}
textarea{color:#33cc33; text-align:center}
h2{color:#008000; font-family:Candara; padding:10px; text-align:center}
input[type=submit],input[type=reset]{background-color:#669900; color:black; padding:12px 25px; text-align:center; border-radius:6px; font-size:16px}
textarea,input[type=text],input[type=date],input[type=time]{border:2px solid orange; border-radius:4px}
</style>
</head>
<body>
<h2> Please give us the following data to complete your booking...! </h2>
<br>
<form action="newcon.php" method="post" onSubmit="window.open('thanking.html')">
<table style="width:100%" border="0">
<tr> <th> Vehicle number </th>
<td> <input type="text" name="v_number" size="100"> </td> </tr>
<tr> <th> Client ID </th>
<td> <input type="text" name="c_id" size="100"> </td> </tr>
<tr>
<th> Date you want to reserve the vehicle </th>
<td> <input type="date" name="date"> </td> </tr>
<tr> <th> Time </th>
<td> From <input type="time" name="from"> To <input type="time" name="to"> </td> </tr>
<tr> <th> Your destination </th> 
<td> <input type="text" name="destination" size="100"> </td> </tr>
<tr>
<th> Where do you want our cab to be arrived </th>
<td> <textarea name="collectpoint" rows="6" cols="100%">
Please give a brief description of where you want our cab to arrive
We'll contact you via provided phone number for more info 
</textarea> </td> </tr>
<tr>
<th> Payment method </th>
<td> <input type="radio" name="payment_method" value="cash"> I'll pay with cash <br>
<input type="radio" name="payment_method" value="card"> I prefer paying with credit/debit card </td> </tr>
<tr> <td colspan="2"> Please be informed that you have to pay the full amount via your selected payment method when we arrive at your place.
Please check whether you've provided all the details correctly </td> </tr>
<tr> <td colspan="2"> Please comfirm your booking by clicking the button below </td> </tr> 
<tr> <td> <input type="submit" value="Comfirm"> </td>
<td> <input type="reset" value="Cancel"> </th> </td>
</table>
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

由于使用过,您的php代码未运行     isset($ _ REQUEST ['submit']) 那返回false,因为      没有name ='submit'

使用此

<input type="submit" name='submit' value="Comfirm">