我已经开始学习php了,我坚持使用php中的“输入”。我即将建立一个注册。
这是我的“输入”代码(signup.php)的引用:
<?php
include_once 'header.php'
?>
<section class="main-container">
<div class="main-wrapper">
<h2>Sign up</h2>
<form class="signup-form" action="includes/signup.inc.php" method="POST">
<input type="text" name="first" placeholder="First Name">
<input type="text" name="last" placeholder="Last Name">
<input type="text" name="e-mail" placeholder="e-mail">
<input type="text" name="uid" placeholder="Username">
<input type="password" name="pwd" placeholder="Password">
<button type="submit" name="submit">
Sign up
</button>
</form>
</div>
</section>
<?php
include_once 'footer.php'
?>
这是我想要开始的代码(signup.inc.php):
<?php
if (isset($_POST['submit'])) {
include_once 'dbh.inc.php';
$first = mysqli_real_escape_string($conn, $_POST['first']);
$last = mysqli_real_escape_string($conn, $_POST['last']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$uid = mysqli_real_escape_string($conn, $_POST['uid']);
$pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
//Error handlers
//Check for empty fields
if (empty($first) || empty($last) || empty($email) || empty($uid) || empty($pwd)) {
header("Location: ../signup.php?signup=empty");
exit();
} else {...
这是我的连接代码(dbh.inc.php):
<?php
$user="root";
$password="";
$conn=mysqli_connect("localhost",$user,$password);
如果我访问我的网站,请单击注册按钮并填写输入框,我立即收到“signup.php?signup = empty”消息。 为什么我的变量是空的?
答案 0 :(得分:1)
乍一看似乎$_POST['email']
返回空,因为那里有一个拼写错误。它应该是$_POST['e-mail']
,因为它在HTML中的名称是电子邮件。
答案 1 :(得分:0)
尝试这个连接到db,如下所示 (dbh.inc.php)
--- NEXT PAIR ---
Key::33:
Value: 88 app 2/8
superman taman, puchong
36100, Malaysia
--- NEXT PAIR ---
Key::22:
Value: bla bla \bla /bla
bla bla
--- NEXT PAIR ---
Key::32:
Value: 45//dsfd//qdsfqsdf
--- NEXT PAIR ---
Key::72D:
Value: Example
在你的php中,然后执行以下操作
$servername = "localhost";
$username = "root";
$password = "";
$Dbconnect = "db_Name";
// Create connection
$conn = new mysqli($servername, $username, $password, $Dbconnect);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
你的电子邮件也应该是include ('dbh.inc.php');
$first = $_POST['first'];
$last = $_POST['last'];
$email = $_POST['e-mail']
$uid = $_POST['uid'];
$pwd = $POST['pwd'];
if (empty($first) || empty($last) || empty($email) || empty($uid) || empty($pwd)) {
header("Location: ../signup.php?signup=empty");
exit();
} else {...