Данные, которые я добавляю в эту форму, не добавляются в базу данных WAMP.

0

Это код 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>
  • 0
    примечание: mysqli_error() требует подключения -> mysqli_error($con)
  • 0
    вы проверяете, if(isset($_REQUEST['submit'])) , но у вашего <input type="submit" value="Comfirm"> нет name="submit" .
Показать ещё 1 комментарий
Теги:
mysqli

1 ответ

0
Лучший ответ

Ваш php-код не запускается, потому что вы использовали isset ($ _ REQUEST ['submit']) И это возвращает false, потому что Not has name = 'submit'

Использовать этот

<input type="submit" name='submit' value="Comfirm">
  • 0
    Это сработало, большое спасибо :)

Ещё вопросы

Сообщество Overcoder
Наверх
Меню