我创建了一个注册页面和一个数据库,目标很简单:
我已经在注册和登录页面中使用了模板,可以插入数据,当我单击“提交”时,只需重新加载即可
signup.php
Infinity
config.php
<?php
session_start();
require 'lib/password.php';
require 'config.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>SignUp</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="application/x-javascript"> addEventListener("load",
function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){
window.scrollTo(0,1); } </script>
<link rel="stylesheet" href="css/signup.css">
<link href="css/style.css" rel="stylesheet" type="text/css" media="all"
/>
<link href="//fonts.googleapis.com/css?
family=Roboto:300,300i,400,400i,700,700i" rel="stylesheet">
</head>
<body>
<!-- main -->
<div class="main-w3layouts wrapper">
<a href="index.html" class="button">Return</a>
<h1>Sign Up</h1>
<div class="main-agileinfo">
<div class="agileits-top">
<form action="signup.php" method="post">
<input class="text" type="text" name="nom" placeholder="nom"
required="">
<input class="text" type="text" name="prenom"
placeholder="prenom" required="">
<input class="text" type="text" name="CIN"
placeholder="CIN" required="">
<input class="text email" type="email" name="email"
placeholder="Email" required="">
<input class="number" type="text" name="numtel1"
placeholder="numtel1">
<input class="number" type="text" name="numtel2"
placeholder="numtel2">
<input class="text" type="password" name="password_1"
placeholder="Password" required="">
<input class="text w3lpass" type="password"
name="password_2" placeholder="Confirm Password" required="">
<input class="Date" type="Date" name="Date"
placeholder="datedenaissance">
<input class="Address" type="text" name="Address"
placeholder="Address">
<div class="wthree-text">
<div class="clear"> </div>
</div>
<input type="submit" name="register" value="Register"></button>
</form>
<p>Have an Account? <a href="login.php"> Login in</a></p>
</div>
</div>
</body>
</html>
Ps。数据库名称为“ stage”
我要向其中插入数据的表是“ utilisateur”
该表包含:
<?php
$name = "";
$prenom = "";
$CIN = "";
$email = "";
$password = "";
$numtel1 = "";
$numtel2 = "";
$Date = "";
$Address = "";
$errors = array();
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "stage";
$connection= mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
if(mysqli_connect_errno()) {
die ("Database connection failed test :" .mysqli_connect_error() .
mysqli_connect_errno() );
}
if (isset($_POST['register'])) {
$name = $_POST['nom'];
$prenom = $_POST['prenom'];
$CIN = $_POST['CIN'];
$email = $_POST['email'];
$password1 = $_POST['password_1'];
$numtel1 = $_POST['numtel1'];
$numtel2 = $_POST['numtel2'];
$Date = $_POST['Date'];
$Address = $_POST['Address'];
$query = "INSERT INTO utilisateur
(`nom`,`prenom`,`CIN`,`email`,`password`,`numtel1`,`Address`) VALUES
('$name','$prenom','$CIN','$email','$password1','$numtel1','$numtel2','$Address')";
mysqli_query($connection,$query);
}
?>
(主要为AI)
ID_UTILISATEUR
(索引)
ID_VILLE
(索引)
ID_TYPE_UTILISATEUR
(索引)
ID_ETAT_UTILISATEUR
(索引)
ID_PAYS
(索引)
ID_SEXE
NOM
PRENOM
CIN
EMAIL
NUMTEL1
NUMTEL2
ADRESSE
提交表单会将数据添加到数据库
答案 0 :(得分:1)
您在表单操作中为相同的页面名称指定了为什么重新加载页面。即
<form action="signup.php" method="post">
应该是这样的:
<form action="config.php" method="post">
请更改它。