如何在数据提交后在同一页面上显示弹出窗口

时间:2015-08-03 06:26:25

标签: php database html5

我有这个html表格



<form class="form" method="post" action="data.php">
					<div class="form-group">
						<input class="form-control input-lg" type="text" placeholder="Full Name" name="name" id="name" required="">
					</div>
					<div class="form-group">
						<input class="form-control input-lg" type="tel" placeholder="Phone Number" name="phone" id="phone" required="">
					</div>
					<div class="form-group">
						<input class="form-control input-lg" type="email" placeholder="Email ID" name="email" id="email" required="">
					</div>
					<div class="form-group">
						<!--<input class="form-control input-lg option" type="date" name="date" value="Date" id="date" required="">-->
						<input type="text" class="form-control input-lg option" name="date" Placeholder="Date" id="datepicker">
					</div>
					<div class="form-group">
						<select class="form-control input-lg option" name="time" id="time" style="padding-left: 10px;color:darkgray;">
						  <option>Time Slot</option>
						  <option>10:00-11:00</option>
						  <option>11:00-12:00</option>
						  <option>12:00-13:00</option>
						  <option>13:00-14:00</option>
						 </select>
					</div>
					<input class="btn btn-success btn-lg" style="margin-left: 30%; margin-top:10px; padding: 5px 16px;" type="submit" value="BOOK ">
&#13;
&#13;
&#13;

这是data.php的代码

&#13;
&#13;
<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

$servername = "localhost";
$username = "root";
$password = "xxxx";
$dbname = "xxxxxxxxxx";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$sql = "INSERT INTO data (name,phone,email,date,time)
VALUES ('$_POST[name]', '$_POST[phone]', '$_POST[email]',  '$_POST[date]', '$_POST[time]')";
if (mysqli_query($conn, $sql)) {
    echo  "<script type='text/javascript'>alert('submitted successfully!')</script>";
}
 else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);


?>
&#13;
&#13;
&#13;

此代码显示在同一窗口上弹出一个丑陋的格式,点击确定后显示空白页面.... / data.php url。我想在同一页面上重定向。

我可以改变弹出式样。我想在页面中间显示弹出窗口。

请帮助解决这些问题..我是新手

1 个答案:

答案 0 :(得分:0)

您无法更改警报弹出窗口的位置。您需要通过window.open打开一个弹出窗口。 使用以下更新的代码重定向回您所需的页面。

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

$servername = "localhost";
$username = "root";
$password = "xxxx";
$dbname = "xxxxxxxxxx";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$sql = "INSERT INTO data (name,phone,email,date,time)
VALUES ('$_POST[name]', '$_POST[phone]', '$_POST[email]',  '$_POST[date]', '$_POST[time]')";
if (mysqli_query($conn, $sql)) 
{
    header('Location:index.php?success=1');
}
 else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);


?>

将标题函数中的yourpage.php替换为您实际的页面名称。 将您的index.html重命名为index.php并对索引文件进行这些更改。

<?php
$get = (isset($_GET['success'])) ? $_GET['success'] : '';
if((!empty($get)) && ($get == 1))
{
    echo  "<script type='text/javascript'>alert('submitted successfully!')</script>";
}
?>

<form class="form" method="post" action="data.php">
                    <div class="form-group">
                        <input class="form-control input-lg" type="text" placeholder="Full Name" name="name" id="name" required="">
                    </div>
                    <div class="form-group">
                        <input class="form-control input-lg" type="tel" placeholder="Phone Number" name="phone" id="phone" required="">
                    </div>
                    <div class="form-group">
                        <input class="form-control input-lg" type="email" placeholder="Email ID" name="email" id="email" required="">
                    </div>
                    <div class="form-group">
                        <!--<input class="form-control input-lg option" type="date" name="date" value="Date" id="date" required="">-->
                        <input type="text" class="form-control input-lg option" name="date" Placeholder="Date" id="datepicker">
                    </div>
                    <div class="form-group">
                        <select class="form-control input-lg option" name="time" id="time" style="padding-left: 10px;color:darkgray;">
                          <option>Time Slot</option>
                          <option>10:00-11:00</option>
                          <option>11:00-12:00</option>
                          <option>12:00-13:00</option>
                          <option>13:00-14:00</option>
                         </select>
                    </div>
                    <input class="btn btn-success btn-lg" style="margin-left: 30%; margin-top:10px; padding: 5px 16px;" type="submit" value="BOOK ">

我还修改了data.php文件,所以一定要使用更新后的代码。