<?php
session_start();
include_once "connect.php";
$fullName = $_POST['fullname'];
$userName = $_POST['username'];
$emailAdd = $_POST['email'];
$passWord = $_POST['password'];
$query = mysql_query("SELECT * FROM users where USERNAME = '$username' ");
$result = mysql_fetch_array($query);
if($fullName == "")
{
?>
<script>
alert("Full Name is required!");
window.location.href = "registeruser.php";
</script>
<?php
}
else
{
if ($userName == "")
{
?>
<script>
alert("Invalid username!");
window.location.href = "registeruser.php";
</script>
<?php
}
else
{
if($userName == $result['USERNAME'])
{
?>
<script>
alert("Username already exists!");
window.location.href = "registeruser.php";
</script>
<?php
}
else
{
if ($emailAdd == $result['EMAIL'])
{
?>
<script>
alert("Email address is required!");
window.location.href = "registeruser.php";
</script>
<?php
}
else
{
if ($passWord == "")
{
?>
<script>
alert("Username is required!");
window.location.href = "registeruser.php";
</script>
<?php
}
else
{
if($_POST['password']==$_POST['confirmpass'])
{
mysql_query("INSERT INTO users (FULLNAME, USERNAME, EMAIL, PASSWORD)
VALUES ('$fullName', '$userName', '$emailAdd', '$passWord')" );
mysql_close();
?>
<script>
alert("Registered Successfully!");
window.location.href = "index.php";
</script>
<?php
}
else
{
?>
<script>
alert("Password and Confirm Password do not match");
window.location.href = "registeruser.php";
</script>
<?php
}
}
}
}
}
}
?>
它能正常工作。但问题是:弹出警告窗口显示在另一个网页而不是当前页面。这没关系,但是将用户引导到没有内容的另一个网页看起来很糟糕。如果您能帮我解决这个问题,并使JavaScript警告窗口仅显示在同一网页上,请告诉我。实际上,我尝试了一些解决方案,例如..
if($fullName == "")
{
echo '<script>';
echo 'alert("Full Name is required!")';
echo 'window.location.href = "registeruser.php"';
echo '</script>';
}
echo 'window.location.href = "registeruser.php"';
。 - Narendrasingh Sisodiamysql_query("SELECT * FROM users where USERNAME = '$username' ")
,因为这会打开SQL注入的漏洞。 - Markus Zellerregistereduser.php
吗? - ImprobabilityCast