【发布时间】:2019-03-04 13:07:50
【问题描述】:
我的 HTML 代码和 PHP 代码位于单独的文档中,因此 HTML 包含文本框等,PHP 文件包含实际的 mySql 命令以将条目写入数据库。我想拥有它,以便在 PHP 代码执行后弹出一个弹出窗口,说“您的输入成功”,然后导航回主页,否则返回我刚刚来自的页面。我的 HTML 表单如下
<form action = "submitEvent.php" method = "post">
Event Name: <br>
<input type = "text" name = "eventname" >
<br>
Event Type: <br>
<input type = "text" name = "eventtype" >
<br>
<!-- need to find a way to get charityID to link the tables
without having the user enter the charityID -->
Charity Number: <br>
<input type = "text" name = "charityid" value="<?php echo $charityid;?>" >
<br>
Contact Details: <br>
<input type = "text" name = "contactdetails" >
<br>
Location: <br>
<input type = "text" name = "eventlocation" >
<br>
Date : <br>
<input type ="date" name ="eventdate">
<br>
<input type = "submit" value = "Submit">
</form>
include 'conn.php';
$eventname = filter_input(INPUT_POST, 'eventname');
$eventtype = filter_input(INPUT_POST, 'eventtype');
$charitynumber = filter_input(INPUT_POST, 'charityid');
$contactdetails = filter_input(INPUT_POST, 'contactdetails');
$eventlocation = filter_input(INPUT_POST, 'eventlocation');
$eventdate = filter_input(INPUT_POST, 'eventdate');
//Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "INSERT
INTO event (eventname, eventtype, charityid, contactdetails, location, date) VALUES ('$eventname', '$eventtype', '$charitynumber', '$contactdetails', '$eventlocation', '$eventdate')";
if ($conn->query($sql) === TRUE) {
header("location: index.php");
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
目前它只是导航回主页,但我还希望在主页上或之前出现通知,以便用户知道记录已成功创建。
【问题讨论】:
标签: javascript php html mysql