Php bootstrap3注册表单
这是我的register.php页面:Php bootstrap3注册表单,php,html,forms,twitter-bootstrap,registration,Php,Html,Forms,Twitter Bootstrap,Registration,这是我的register.php页面: <!DOCTYPE html> <html lang="it"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Circolari 2.0</title> <link rel=stylesheet typ
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Circolari 2.0</title>
<link rel=stylesheet type="text/css" href="css/bootstrap.css">
<link rel=stylesheet type="text/css" href="css/styles.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="form-signup">
<b><h1 class="text-center">Registrazione</h1></b>
<br>
<form action="register.php" method="post">
<div class="form-group">
<div class="left-inner-addon">
<i class="glyphicon glyphicon-user"></i>
<input class="form-control focus" type="text" placeholder="Nome" name="nome">
</div>
</div>
<div class="form-group">
<div class="left-inner-addon">
<i class="glyphicon glyphicon-user"></i>
<input class="form-control focus" type="text" placeholder="Cognome" name="cognome">
</div>
</div>
<div class="form-group">
<div class="left-inner-addon">
<i class="glyphicon glyphicon-envelope"></i>
<input class="form-control focus" type="text" placeholder="Email" name="email">
</div>
</div>
<div class="form-group">
<div class="left-inner-addon">
<i class="glyphicon glyphicon-lock"></i>
<input class="form-control focus" type="password" placeholder="Password" name="password">
</div>
</div>
<button class="btn btn-info" type="submit" name="submit_button">Registrati</button>
<a class="btn btn-warning" href="index.php">Home</a>
</form>
</div>
</div>
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
</body>
</html>
<?php
if (isset($_POST['submit_button']))
{
// Definisco le variabili Nome, Cognome, Email e Password
$nome=$_POST['nome'];
$cognome=$_POST['cognome'];
$email=$_POST['email'];
$password=$_POST['password'];
if ($nome=="" or $cognome="" or $email="" or $password="")
{
echo "Tutti i campi sono obbligatori";
}
else
{
// Includo il file di configurazione
include('config.php');
// Connessione al database
$conn=mysqli_connect("$db_host", "$db_username", "$db_password", "$db_name") or die (mysqli_error($conn));
// Controllo se Email è già registrata
$stmt=$conn->prepare("SELECT * FROM $tbl_name WHERE Email=?");
$stmt->bind_param("s", $email);
$stmt->execute();
$result=$stmt->get_result();
// Conto i risultati
$count=$result->fetch_assoc();
// Se Email e Password combaciano, otterrò un solo risultato
if($count==1)
{
echo "Utente già registrato!";
}
else
{
// Query Database
$stmt=$conn->prepare("INSERT INTO $tbl_name (Nome, Cognome, Email, Password) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $nome, $cognome, $email, $password);
$stmt->execute();
$result=$stmt->get_result();
if ($stmt->execute())
{
echo "Registrazione effettuata con successo!";
echo ($nome);
echo ($cognome);
echo ($email);
echo ($password);
}
else
{
echo (mysqli_error($conn));
}
}
}
}
?>
问题是,当我单击SUBMIT按钮时,在数据库中除了“Nome”之外,我有所有的空白列。我真的不明白这个问题。
附言:我添加了所有变量的回声,事实上屏幕上只打印$nome。谢谢大家! 我很确定您的输入字段需要有一个唯一的id=xxx,否则它将不会以post的形式发送echo$sql并查看它包含的内容。您确实需要使用准备好的语句,您对脚本上的SQL注入攻击非常开放。这就是我在回显变量和SQL查询时看到的:Registrazione effettuata con successo!Cristiano插入Uteni Nome、Cognome、电子邮件、密码值“Cristiano”、。另一件奇怪的事情是,如果我注册同一封电子邮件,我就不能注册,因为脚本说用户已经存在,我会在PHP脚本的第一部分检查电子邮件,但如果我只签入数据库,则会显示变量$nome,其他变量为blank。我用语句更新代码以防止MySQL注入