如何在简单的PHP中发布在同一页面中? [英] How to Post in the Same Page in Simple PHP?

查看:86
本文介绍了如何在简单的PHP中发布在同一页面中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试仅使用PHP创建注册系统.这是一个例子.但是我想我做错了什么.我试图在StackOverFlow帖子中找到类似的解决方案,但没有得到确切的解决方案.如果有人能帮助我在下面的代码中找到错误,那将是真的.

I am trying to create a Registration System using only PHP. This is an example of that. But I think I have done something wrong. I tried to find similar solution in StackOverFlow posts but didn't get any exact solution. It would be really get if someone would help me to find the error in my code below.

<?php
// POST HANDLER -->

if(isset($_POST['registerForm']))
{
    conFunc(); // Connection Function

    $userid = $_POST['userid'];
    $name = $_POST['name'];

    $getUserId = mysql_query("SELECT * FROM `user` WHERE `userid` = '".$userid."'");
    $id = mysql_fetch_array($getUserId);

    if($id)
    {
        echo "This User ID is Already Available on the System, Please Choose Something Else!";
    }
    else
    {

        $query = mysql_query("INSERT INTO `user` (`userid`, `name`");

        if($query)
        {
            echo "A New User is Registered Successfully:<br /><br />";
            echo "<b>User ID:</b> " . $userid . "<br />";
            echo "<b>User Name:</b> " . $name . "<br />";
        }
        else
        {
            echo "There is an Error while Saving: " . mysql_error();
            echo "<br />Please click on Create User from menu, and try again<br /><br />.";
        }

    }
    exit;
}
// POST HANDLER -->
?>

<!-- FORM GOES BELOW -->

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="registerForm">

<table style="width: 100%">
    <tr>
        <td>User ID</td>
        <td><input name="userid" type="text" style="width: 300px" /><br /></td>
    </tr>
    <tr>
        <td>Name</td>
        <td><input name="name" type="text" style="width: 300px" /><br /></td>
    </tr>
    <tr>
        <td></td>
        <td><input style="width: 130px; height: 30px" type="submit" name="submit" value="Register Now" /><br /></td>
    </tr>
</table>

</form>

推荐答案

您必须检查提交"按钮是否已设置.

You have to check the submit button is set or not.

if(isset($_POST['registerForm']))

应该是

if(isset($_POST['submit'])) {
    // your php code
} else {
    // your html code

}

这篇关于如何在简单的PHP中发布在同一页面中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆