gpt4 book ai didi

php - 插入数据库的 HTML 表单和 PHP 脚本不起作用

转载 作者:行者123 更新时间:2023-11-29 06:06:03 25 4
gpt4 key购买 nike

我正在尝试将一个新用户插入到我的数据库中,但是 php 总是失败,我所做的 issets 总是返回 false 所以它没有插入,我不知道为什么,我敢打赌这是一个基本的修复,我有点沮丧..

HTML 页面

 <html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="./css/bootstrap.min.css" >
<link rel="stylesheet" href="./css/orlando.css" >
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content=" Pagina Inicial ">

</head>

<body>

<div id="wrapper">
<!-- Sidebar -->
<nav class="navbar navbar-inverse navbar-fixed-top" id="sidebar-wrapper" role="navigation">
<ul class="nav sidebar-nav">
<li class="sidebar-brand">
<a href="#">
<img src="./img/logo2.png" alt="">
</a>
</li>
<li>
<a href="index.html">Login</a>
</li>
<li>
<a href="register.html">Register</a>
</li>
<li>
<a href="about.html">About</a>
</li>
<li>
<a href="profile.html">Profile</a>
</li>
<li>
<a href="matchhistory.html">Match History</a>
</li>
<li>
<a href="leaderboard.html">Leaderboard</a>
</li>
<li>
<a href="contacts.html">Contacts</a>
</li>
<li>
<a href="#">Logout</a>
</li>
</ul>
</nav>
<!-- /#sidebar-wrapper -->

<!-- Page Content -->
<div id="page-content-wrapper">
<nav class="navbar navbar-default navbar-static-top">

<div class="container" style="width: 100%;">
<button type="button" class="hamburger is-closed" data-toggle="offcanvas">
<span class="hamb-top"></span>
<span class="hamb-middle"></span>
<span class="hamb-bottom"></span>
</button>
<div class="navbar-header">
<a class="navbar-brand" href="./index.html"target="_self" style="margin-left: 55px;"> <img src="./img/logo.png" alt=""></a>
</div>
</div>
</nav>

<form class="form-signin" action="register.php">
<h2 class="form-signin-heading">Register</h2>
<input type="text" class="form-control" name="name" placeholder="name" required="" autofocus="" />
<input type="text" class="form-control" name="nickname" placeholder="nickname" required="" autofocus="" />
<input type="text" class="form-control" name="email" placeholder="email" required="" autofocus="" />
<input type="password" class="form-control" name="password" placeholder="password" required=""/>
<label class="checkbox">
<input type="checkbox" value="remember-me" id="rememberMe" name="rememberMe"> Remember me
</label>
<button class="btn btn-lg btn-primary btn-block" type="submit">Register</button>
</form>

<!-- /#page-content-wrapper -->
</div>
</div>

<!-- /#wrapper -->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
<script src="./js/master.js"></script>
</html>

PHP 脚本:

   <?php

define("DB_HOST", "");
define("DB_USER", "");
define("DB_PASSWORD", "");
define("DB_DATABASE", "");

$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE) or die('Oops');
//verificar se a ligação foi feita com sucesso
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

if (isset($_POST['name']) && isset($_POST['nickname']) && isset($_POST['email']) && isset($_POST['password'])) {

echo "isset";
$name = $_POST['name'];
$nickname = $_POST['nickname'];
$email = $_POST['email'];
$password = $_POST['password'];

$query = "INSERT INTO users(name, nickname, email, password) VALUES ('$name', '$nickname', '$email', '$password' )";
$insert = mysqli_query($con, $query) or die ('Error');

if ($insert) {
echo "sucess";
} else {
echo "RIP";
}
} else {
echo "error";
}

?>

它回应了“错误”。

谢谢。

最佳答案

您需要将 method="post" 添加到您的表单中......!

所有条件都失败的原因是 $_POST 为空。您没有发布任何数据,因为默认表单方法是 GET

关于php - 插入数据库的 HTML 表单和 PHP 脚本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41625908/

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