dongxing6802 2015-10-03 15:13
浏览 54
已采纳

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

I'm new to Web programming it might be a silly doubt but still asking.

Edited my previous question.I have Register.html page and Welcome.php. In Register.html i have a form in which if username is not entered then call alert('Enter name'). Otherwise go to Welcome.php page print his username which he entered.

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'];
?>
  • 写回答

1条回答 默认 最新

  • duanlan7903 2015-10-03 15:28
    关注

    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.

    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...

    //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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?