gpt4 book ai didi

PHP 表单未发布到 MySQL 数据库

转载 作者:行者123 更新时间:2023-11-29 19:14:41 26 4
gpt4 key购买 nike

我正在为我的雇主创建一个新的预订系统,其中填写表格并将数据输入预先构建的 MySQL 数据库。

老实说,我不确定我做错了什么。最初,数据不会发布到数据库中,但表单似乎已提交。现在,表单仅提交到一个白页。我将在下面提交完整的页面代码,因为那里没有妥协的数据,希望有人能够提供帮助。

<head>
<title>&nbsp;&nbsp;Moat Laptop Bookinge&nbsp;&nbsp;</title>
<?php
if (isset($_POST['submitted'])) {

include('booking_db.php');

$name = $_POST['name'];
$out = $_POST['out'];
$in = $_POST['in'];
$sqlinsert = "INSERT INTO Future (name, out, 'in') VALUES ('$name', '$out', '$in')";

if (!mysqli_query ($dbcon, $sqlinsert)) {
die('error inserting new record');
}
$newrecord = "Laptop has been successfully Booked!";
}
?>

<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

<script>
$(document).ready(function() {
$("#datepicker").datepicker();
});
</script>

<script>
$(document).ready(function() {
$("#datepicker2").datepicker();
});
</script>
</head>

<body style="background-height: 100%;background-width: 100%;background: #141E30;background: -webkit-linear-gradient(to left, #141E30 , #243B55);background: linear-gradient(to left, #141E30 , #243B55);">
<div id="logo" style="font-family: Tw Cen MT; font-weight: Bold; position: fixed; color: white; left: 650px;top: 35px; font-size: 80px;text-shadow: 3px 3px #c7c7c7;">
Book a Laptop
</div>
<div id="content_box" style="background-color: white;position: fixed; left: 450px;top: 135px; width:60%; height: 70%; border-radius: 3px;">
<center>
<form method="post" action="book.php" style="font-family: Bodoni MT;">
<input type="hidden" name="submitted" value="true" />
<br />
<br />
<b><legend>First Name and First Letter of Surname</legend></b>
<input type="text" name="name" value="Ex. James T" />
<br/>
<br />

<b><legend>When will you need to collect the device?</legend></b>
<input id="datepicker2" name="out" />
<br/>
<br />

<b><legend>When will you return the device?</legend></b>
<input id="datepicker" name="in" />

<br />
<input type="submit" value="Confirm Booking" />



</center>
<?php
echo $newrecord
?>

</div>

</body>

如果您在合理范围内需要更多信息,请随时询问。

编辑这个问题已经解决了,我无法标记答案,因为这是我的答案,我必须等待 2 天。谢谢您的所有回答。

最佳答案

include('booking_db.php'); 行可能存在问题。您应该在页面顶部提及 error_reporting(E_ALL);,并尝试调试:

error_reporting(E_ALL);

if (isset($_POST['submitted'])) {

var_dump(file_exists('booking_db.php')); //check if you get true or false

require 'booking_db.php'; // Change include to required
echo "Test";
exit;
$name = $_POST['name'];
echo $name; // Check
$out = $_POST['out'];
$in = $_POST['in'];
$sqlinsert = "INSERT INTO Future (name, out, 'in') VALUES ('$name', '$out', '$in')";

var_dump($dbcon); // check

if (!mysqli_query ($dbcon, $sqlinsert)) {
die('error inserting new record');
}
$newrecord = "Laptop has been successfully Booked!";
}

请检查表单提交后您收到的内容。

关于PHP 表单未发布到 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42805127/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com