简体   繁体   English

注册页面,验证并将数据发送到php文件

[英]Registration Page,validation and send data to php file

I'm new to Web programming it might be a silly doubt but still asking.我是 Web 编程的新手,这可能是一个愚蠢的疑问,但仍然在问。

Edited my previous question.I have Register.html page and Welcome.php.编辑了我之前的问题。我有 Register.html 页面和 Welcome.php。 In Register.html i have a form in which if username is not entered then call alert('Enter name').在 Register.html 我有一个表格,如果没有输入用户名,则调用 alert('Enter name')。 Otherwise go to Welcome.php page print his username which he entered.否则去 Welcome.php 页面打印他输入的用户名。

My problem is if i don't enter the username and still submit the form then the alert message doesn't pop up.我的问题是,如果我不输入用户名并仍然提交表单,则不会弹出警报消息。

**This is my Register.html code** 
<!DOCTYPE HTML>
<html>
<head>
<script>
function validation(){

if(document.getElementById('username').value=="")
{
    alert('Enter name');
}

</script>
</head>
<body>

<h1>Enter the details</h1>
<form method="post" action="Welcome.php">
<table >
<tr>
    <td>Username:</td>
    <td><input type="text" name="username" id="username"></td>

</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pass" id="pass" ></td>
</tr>
<tr>
<td>Confirm Password:</td>
<td><input type="password" name="Repass" id="Repass" ></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" id="email"></td>
</tr>
<tr>
    <td></td>
    <td><input type="button" value="register" onclick="validation();"></td>

</tr>
</table>
</form>
</body>

</html>



**This is my Welcome.php**
<?php
echo "Welcome".$_POST['username'];
?>

Your answer seems to be lacking a lot of required information that is needed to answer your question.您的回答似乎缺少许多回答您的问题所需的必需信息。 However from what you have currently in your question and from personal experience I would probably just use PHP for the result your looking for.但是,从您目前的问题和个人经验来看,我可能只会使用 PHP 来获得您想要的结果。

So let's say your form resembles something like this...所以让我们说你的表格类似于这样的东西......

<form action="" method="post" id="register">
    <input type="text" name="username" placeholder="Your username" />
    <input type="email" name="email" placeholder="Your email address" />
    <input type="password" name="password" placeholder="Your password" />
    <input type="submit" value="Join" />
</form>

I did try and do something similar to this in one of my previous projects, but in the end I did something like this...在我之前的一个项目中,我确实尝试过做类似的事情,但最后我做了这样的事情......

<?php if($register_success = 1) { ?>
<h1>Welcome <?php echo $_POST['username']; ?></h1>
<p>This is a static registration message with instructions on what to do further...</p>
<?php } else { ?>
<form action="" method="post" id="register">
    <input type="text" name="username" placeholder="Your username" />
    <input type="email" name="email" placeholder="Your email address" />
    <input type="password" name="password" placeholder="Your password" />
    <input type="submit" value="Join" />
</form>
<?php } ?>

and to receive output like this validate with PHP and set a the value of $register_success like so...并接收这样的输出,用 PHP 验证并像这样设置$register_success的值......

//In no errors statement where you would register the user set the value of $register_success to 1

} else {
    //Register the user
    $register_success = 1;
}

I hope that this answer helped your question.我希望这个答案对你的问题有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM