【发布时间】:2014-08-07 19:37:12
【问题描述】:
嗨,我是一名编程初学者,我正在尝试在我的网站上制作一个简单的注册功能,一个简单的表格供用户填写,然后它应该将数据存储在我的数据库中,问题是一切正常(我认为):) 但数据/用户信息不存储。
<?php
include ("./inc/header.inc.php") $reg = @$_POST['reg'];
$fn = ""; //first name
$ln = ""; //Last name
$un = ""; //User name
$em = ""; //Email
$em2 = ""; //Email2
$pswd = ""; //Password
$pswd2 = ""; //Password 2
$d = ""; //sign up date
// registrering av nya användare
// ucheck kontrollerar om användaren redan finns
$fn = strip_tags(@$_POST['first_name']);
$ln = strip_tags(@$_POST['last_name']);
$un = strip_tags(@$_POST['Username']);
$em = strip_tags(@$_POST['Email']);
$em2 = strip_tags(@$_POST['Email2']);
$pswd = strip_tags(@$_POST['Password']);
$pswd2 = strip_tags(@$_POST['Password2']);
$d = date("Y-n-d");
if ($reg)
{
if ($em == $em2)
{
$u_check = mysqli_query($mysqli, "SELECT Username FROM users WHERE Username='$un'");
$check = mysqli_num_rows($u_check);
if ($check == 0)
{
if ($fn && $ln && $un && $em && $em2 && $pswd && $pswd2)
{
if ($pswd == $pswd2)
{
if (strlen($un) > 25 || strlen($fn) > 25 || strlen($ln) > 25)
{
echo "The maximum limit for Username/last name and first name is 25 characters :(";
}
else
{
if (strlen($pswd) > 30 || strlen($pswd) < 5)
{
echo " Your password must be more than 5 characters or less then 30 characters :(";
}
else
{
// kryptering av password 1 och 2 med hjälp av md5 innan det sätts i databasen
$pswd = md5($pswd);
$pswd2 = md5($pswd2);
$query = mysqli_query($mysqli, "INSERT INTO users VALUES (``,`$un`,`$fn`,`$ln`,`$em`,`$pswd`,`$d`,`0`)");
die("<h2>You are now a member of the village</h2> Login to get started...");
}
}
}
else
{
echo "Your passwords don´t match :(";
}
}
else
{
echo "Please fill in all of the fields";
}
}
else
{
echo "Username already taken ...";
}
}
else
{
echo "Your emails dont match :( ";
}
}
?>
<div style="width: 1000px; margin:0px auto 0px auto;">
<table>
<tr>
<td width="60%" valign="top">
<h2>Join Today!<h2>
</td>
<td width="40%" valign="top">
<h2>Enter Your information and sign up today!<h2>
<form action="#" method= "POST">
<input type="text" name="first_name" Size:"30" placeholder="Firstname"/><br/><br/>
<input type="text" name="last_name" Size:"30" placeholder="Lastname"/><br/><br/>
<input type="text" name="Username" Size:"30" placeholder="Username"/><br/><br/>
<input type="text" name="Password" Size:"30" placeholder="Password"/><br/><br/>
<input type="text" name="Password2" Size:"30" placeholder="Password Confirmation"/><br/><br/>
<input type="text" name="Email" Size:"30" placeholder="Email"/><br/><br/>
<input type="text" name="Email2" Size:"30" placeholder="Email Confirmation"/><br/><br/>
<input type="Submit" name="reg" Size:"30" placeholder="Sign-up!">
</form>
</td>
</tr>
<?php include ( "./inc/footer.inc.php" )?>
【问题讨论】:
-
去掉值周围的勾号并使用引号。
-
另外,你正在使用
@来抑制错误,这就是它的“at”;)这是事实,Jack。没有给出答案,原因有很多。 -
由于您不检查错误,请使用error reporting。
-
欢迎来到 StackOverflow!如果您是初学者,那么您很有可能不再学习使用那些已弃用的 mysql_* 函数。最好从 PDO 或 MySQLi 开始。从一开始就使用带有占位符的准备好的语句,将您的输入值绑定到这些占位符。你不会后悔的!
标签: php html mysql post mysqli