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 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件