我对PHP不太好,但我需要做一个用户注册表格,这是我迄今为止所做的事情
email_B
我可以看到消息"我在"在我的屏幕上,但我也得到了#34;失败"消息,因为它没有在数据库中插入任何内容。我一直在努力寻找错误,但到目前为止还没有。错误应该在这里
<!doctype html>
<html>
<head>
<title>Register</title>
</head>
<body>
<p><a href="register.php">Register</a> | <a href="login.php">Login</a></p>
<h3>Formulario de registro</h3>
<form action="" method="POST">
Usuario: <input type="text" name="login"><br />
Contrasena: <input type="password" name="password"><br />
Email: <input type="text" name="email"><br />
Sexo: <input type="text" name="sex"><br />
Edad: <input type="text" name="age"><br />
Telefono: <input type="text" name="phone"><br />
Pais: <input type="text" name="country"><br />
Ciudad: <input type="text" name="city"><br />
Direccion: <input type="text" name="address"><br />
<input type="submit" value="Register" name="submit" />
</form>
<?php
if(isset($_POST["submit"])){
if(!empty($_POST['login']) && !empty($_POST['password'])) {
$login=$_POST['login'];
$password=$_POST['password'];
$email=$_POST['email'];
$sex=$_POST['sex'];
$age=$_POST['age'];
$phone=$_POST['phone'];
$country=$_POST['country'];
$city=$_POST['city'];
$address=$_POST['address'];
$con=mysqli_connect('localhost','root','','registro_usuarios') or die(mysql_error());
$sql="SELECT * FROM usuario ";
$result = mysqli_query($con,$sql);
if(mysqli_num_rows($result)>=0)
{
echo "I'm in";
$sql="INSERT INTO usuario (login,password,email,sex,age,phone,country,city,address)
VALUES('$login','$password','$password','$email','$sex','$age','$country','$city','$address')";
$result=mysqli_query($con,$sql);
if($result){
echo "Account Successfully Created";
} else {
echo "Failure!";
}
} else {
echo "That username already exists! Please try again with another.";
}
} else {
echo "All fields are required!";
}
}
?>
</body>
</html>
我已经检查过我的数据库中的所有值,以防万一你好奇并且没有拼写错误。
由于
答案 0 :(得分:0)
你在sql insert中错了。
你的sql:
$sql="INSERT INTO usuario (login,password,email,sex,age,phone,country,city,address) VALUES('$login','$password','$password','$email','$sex','$age','$country','$city','$address')";
$result=mysqli_query($con,$sql);
查看值行与插入字段不匹配。你输入两次$ password,而不是$ phone。
如果仍然是错误,您可以添加此内容以了解查询有什么问题:
if(mysqli_query($con,$sql))
{
echo 'Success'.'</br>';
}
else
{
echo 'Fail';
echo "Error Description : ".mysqli_error($con);
}