我知道这可能是一个重复的帖子,虽然我不确定如何在我的上下文中使用帖子答案。我试图将注册的字段发布到数据库,但是如果它们被采用(仅用户名和电子邮件),则返回到用户可以编辑错误信息的表单。有人可以帮忙吗?
我知道我正在使用已弃用的标签,这适用于大学项目
if (isset($_POST['firstname'], $_POST['surname'], $_POST['email'], $_POST['username'], $_POST['password'], $_POST['interest'])){
$firstname = ($_POST['firstname']);
$surname = ($_POST['surname']);
$username = ($_POST['username']);
$password1 = ($_POST['password']);
$email = ($_POST['email']);
$interest = ($_POST['interest']);
$result = mysql_query("INSERT INTO user (firstname,surname,username,password,email,interestarea,user_type) VALUES ('$firstname','$surname','$username','$password1','$email','$interest','normal')");
}
if (isset($_POST['submit']))
{
?>
<script>window.location='redirect.html';</script>
<?php
}
?>
我确实有类似的东西,但这不起作用
$query2="SELECT * FROM user WHERE username='$username'";
$result2=mysql_query($query2);
$num=mysql_numrows($result2);
if ($num!=0)
{
echo "That username has already been taken, please try again<br>
<a href='register.php'>Register</a>";
exit();
}
答案 0 :(得分:3)
该功能为mysql_num_rows
而非mysql_numrows
:
$num = mysql_num_rows($result2);
正如该页面还告诉您的那样,从PHP 5.5.0开始,此方法不再使用。建议开始使用mysqli_*或PDO