<div id="JoinModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal Content -->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Join </h4>
</div>
<div class="modal-body">
<form action="demo4.php" method="POST">
<div class="form-group">
<label><b>Email address:</b></label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter Email" class="form-control input-sm">
</div>
<div class="form-group">
<label><b>Password:</b></label>
<input type="password" id="password" name="password" placeholder="Enter Password" class="form-control input-sm">
</div>
<div class="form-group">
<label class="sr-only" for="password">Password</label>
<input type="password" id="password" name="password" placeholder="Repeat Password" class="form-control input-sm">
</div>
<div class="checkbox">
<label style="color:black;">
<input type="checkbox"><small> Remember Me</small>
</label>
</div>
<button type="submit" id="signIn" class="btn btn-info btn-sm">Sign In</button>
<button type="button" id="cancelModal" class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
</form>
</div>
</div>
</div>
</div>
这是php代码:
<?php // <-- if you don't open the php tag, your code won't work
$servername="localhost";
$dbname="schema1";
$password="1234";
$user="root";
$port ="3306";
$conn = new mysqli($servername,$user,$password);
if ($conn->connect_error) {
die("connection failed:" .$conn->connect_error);
}
echo "Connected successfully to Mysql server!";
$db_selected = mysqli_select_db($conn,$dbname);
if (!$db_selected){
die("Cant use db: " .mysql_error());
}
echo 'Connected successfully to database';
// $email = mysqli_real_escape_string($conn,$_REQUEST)['email'];
// echo ( "email is:" .$email) ;
// $password = mysqli_real_escape_string($conn,$_REQUEST)['password'];
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "INSERT INTO Members (email,password)
VALUES ('$email', '$password')";
if (!mysqli_query($conn,$sql)) {
die('Error!!: ' . mysqli_error($conn));
}
else {
echo "Success:";
}
$conn->close();
?>
当我在浏览器中输入用户名和密码时,我收到此错误:(它只显示phpfile)
尝试通过HTML和php将数据插入Mysql数据库时出错
connect_error) { die("connection failed:" .$conn->connect_error); } echo "Connected successfully to Mysql server!"; $db_selected = mysqli_select_db($conn,$dbname); if (!$db_selected){ die("Cant use db: " .mysql_error()); } echo 'Connected successfully to database'; // $email = mysqli_real_escape_string($conn,$_REQUEST)['email']; // echo ( "email is:" .$email) ; // $password = mysqli_real_escape_string($conn,$_REQUEST)['password']; $email = $_POST['email']; $password = $_POST['password']; $sql = 'INSERT INTO `Members` (`email`,`password`) VALUES (:email, :password)'; if (!mysqli_query($conn,$sql)) { die('Error!!: ' . mysqli_error($conn)); } else { echo "Success:"; } $conn->close(); ?>
任何帮助都将不胜感激。谢谢!
答案 0 :(得分:0)
连接失败,因为您忘记编写_connect 这是正确的
$conn = mysqli_connect($servername,$user,$password);
答案 1 :(得分:0)
这些错误表明未建立数据库连接。首先检查是否仍然发现错误检查您的文件是否为.php。
按此检查
$conn = mysqli_connect($servername,$user,$password, $dbname);
if($conn){
echo "Connection Success";
}else{
echo "Connection Failed";
}