【发布时间】:2016-07-06 08:28:26
【问题描述】:
我有 2 个文件,一个名为“index.html”,另一个名为“student.php”。 index.html代码如下所示:
<!DOCTYPE html>
<html>
<head>
<title>insert data in database using mysqli</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="main">
<h1>Insert data into database using mysqli</h1>
<div id="login">
<h2>Student's Form</h2>
<hr/>
<Form Name ="form1" Method ="POST" ACTION = "student.php">
<!--<form action="" method="post"> -->
<label>Student Name :</label>
<input type="text" name="stu_name" id="name" required="required" placeholder="Please Enter Name"/><br /><br />
<label>Student Email :</label>
<input type="email" name="stu_email" id="email" required="required" placeholder="john123@gmail.com"/><br/><br />
<label>Student City :</label>
<input type="text" name="stu_city" id="city" required="required" placeholder="Please Enter Your City"/><br/><br />
<input type="submit" value=" Submit " name="submit"/><br />
</form>
</div>
<!-- Right side div -->
</div>
</div>
</body>
</html>
学生.php:
<?php
if(isset($_POST["submit"])){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "college";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO students (student_name, student_email, student_city)
VALUES ('".$_POST["stu_name"]."','".$_POST["stu_email"]."','".$_POST["stu_city"]."')";
if ($conn->query($sql) === TRUE) {
echo "<script type= 'text/javascript'>alert('New record created successfully');</script>";
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
}
$conn->close();
}
?>
输入学生姓名、电子邮件和地址后,我点击提交按钮。下一页出现以下错误:Cannot POST /http-services/emulator-webserver/ripple/userapp/x/C/xampp/htdocs/xampp/please/www/student.php。我之前已经测试过数据库连接,并且应用程序能够连接到数据库,所以这不是问题。我的代码有问题吗?
【问题讨论】:
-
是否可能需要配置 xampp 以允许文件使用
POST方法?
标签: javascript php html mysql mysqli