Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从已填充的表单中获取信息_Php_Mysql - Fatal编程技术网

Php 如何从已填充的表单中获取信息

Php 如何从已填充的表单中获取信息,php,mysql,Php,Mysql,我试图使用submit按钮更新数据库记录,但是从中获取信息的表单本身已被另一个submit按钮填充 下面是PHP: if (isset($_POST['edit'])) { $editUser = User::locate($_POST['userSelect']); $setCompany = Company::findCompany(); $exCompanyId = $editUser->user_company_id; $isAdmin = $edi

我试图使用submit按钮更新数据库记录,但是从中获取信息的表单本身已被另一个submit按钮填充

下面是PHP:

if (isset($_POST['edit']))
{
    $editUser = User::locate($_POST['userSelect']);
    $setCompany = Company::findCompany();
    $exCompanyId = $editUser->user_company_id;
    $isAdmin = $editUser->user_admin;
    $eUserFirstname = $editUser->user_firstname;
    $eUserLastname = $editUser->user_lastname;
    $eUserUsername = $editUser->user_username;
    $eUserEmail = $editUser->user_email;
    $eUserCompany = $editUser->user_company;
    $adminArray = array("Yes","No");
    if ($exCompanyId > NULL)
    {
        $exCompany = Company::locateId($exCompanyId);
        $companyValue = $exCompany->company_name;
    }
    else
    {
        $companyValue = "";
    }
    if ($isAdmin > 0)
    {
        $userAdmin = $adminArray[0];

    }
    else
    {
        $userAdmin = $adminArray[1];
    }
}
if (isset($_POST['confirm']))
{
    $updateUserRecord = User::locate($eUserUsername);
    $newCompanyValue = $_POST['setCompany'];
    $isAdmin = $_POST['userAdmin'];
    $newCompany = Company::locate($newCompanyValue);
    $companyId = $newCompany->company_id;

    $updateUserRecord->user_company_id = $companyId;
    $updateUserRecord->user_admin = $isAdmin;

    $editUser->updateUserAdmin();

    $message = "You have successfully updated the user account";
    echo "<script type='text/javascript'>alert('$message');</script>";
}
<form action="" method="post">
            <p>
                <label>First Name:</label>
                <label><?php echo $eUserFirstname ?></label>
            </p>
            <p>
                <label>Last Name:</label>
                <label><?php echo $eUserLastname ?></label>
            </p>
            <p>
                <label>Username:</label>
                <label><?php echo $eUserUsername ?></label>
            </p>
            <p>
                <label>Email Address:</label>
                <label><?php echo $eUserEmail ?></label>
            </p>
            <p>
                <label>User Company:</label>
                <label><?php echo $eUserCompany ?></label>
            </p>
            <p>
                <label>Set Company:</label>
                <select name="setCompany">
                    <option><?php echo $companyValue ?></option>
                    <?php
                    foreach ($setCompany as $srow)
                    {
                        ?>
                        <option id="<?=
                        $srow->company_id
                        ?>">
                            <?=
                            $srow->company_name
                            ?>
                        </option>
                        <?php
                    }
                    ?>
                </select>
            </p>
            <p>
                <label>Administrator:</label>
                <select name="userAdmin">
                    <option><?php echo $userAdmin ?></option>
                    <?php
                    foreach ($adminArray as $arow)
                    {
                        ?>
                        <option>
                            <?=
                            $arow
                            ?>
                        </option>
                        <?php
                    }
                    ?>
                </select>
            </p>
            <input type="submit" name="cancel" value="Cancel">
            <input type="submit" name="confirm" value="Confirm">
            </br>
        </form>
if(isset($\u POST['edit']))
{
$editUser=User::locate($_POST['userSelect']);
$setCompany=Company::findCompany();
$exCompanyId=$editUser->user\U COMPANYID;
$isAdmin=$editUser->user\u admin;
$eUserFirstname=$editUser->user\u firstname;
$eUserLastname=$editUser->user\u lastname;
$eUserUsername=$editUser->user\u用户名;
$eUserEmail=$editUser->user\u email;
$eUserCompany=$editUser->user\u company;
$adminArray=array(“是”、“否”);
如果($exCompanyId>NULL)
{
$exCompany=Company::locateId($exCompanyId);
$companyValue=$exCompany->company\u name;
}
其他的
{
$companyValue=“”;
}
如果($isAdmin>0)
{
$userAdmin=$adminArray[0];
}
其他的
{
$userAdmin=$adminArray[1];
}
}
如果(isset($_POST['confirm']))
{
$updateUserRecord=User::locate($eUserUsername);
$newCompanyValue=$_POST['setCompany'];
$isAdmin=$\u POST['userAdmin'];
$newCompany=Company::locate($newCompanyValue);
$companyId=$newCompany->company\u id;
$updateUserRecord->user\u company\u id=$companyId;
$updateUserRecord->user\u admin=$isAdmin;
$editUser->updateUserAdmin();
$message=“您已成功更新用户帐户”;
回显“警报('$message');”;
}
HTML代码如下所示:

if (isset($_POST['edit']))
{
    $editUser = User::locate($_POST['userSelect']);
    $setCompany = Company::findCompany();
    $exCompanyId = $editUser->user_company_id;
    $isAdmin = $editUser->user_admin;
    $eUserFirstname = $editUser->user_firstname;
    $eUserLastname = $editUser->user_lastname;
    $eUserUsername = $editUser->user_username;
    $eUserEmail = $editUser->user_email;
    $eUserCompany = $editUser->user_company;
    $adminArray = array("Yes","No");
    if ($exCompanyId > NULL)
    {
        $exCompany = Company::locateId($exCompanyId);
        $companyValue = $exCompany->company_name;
    }
    else
    {
        $companyValue = "";
    }
    if ($isAdmin > 0)
    {
        $userAdmin = $adminArray[0];

    }
    else
    {
        $userAdmin = $adminArray[1];
    }
}
if (isset($_POST['confirm']))
{
    $updateUserRecord = User::locate($eUserUsername);
    $newCompanyValue = $_POST['setCompany'];
    $isAdmin = $_POST['userAdmin'];
    $newCompany = Company::locate($newCompanyValue);
    $companyId = $newCompany->company_id;

    $updateUserRecord->user_company_id = $companyId;
    $updateUserRecord->user_admin = $isAdmin;

    $editUser->updateUserAdmin();

    $message = "You have successfully updated the user account";
    echo "<script type='text/javascript'>alert('$message');</script>";
}
<form action="" method="post">
            <p>
                <label>First Name:</label>
                <label><?php echo $eUserFirstname ?></label>
            </p>
            <p>
                <label>Last Name:</label>
                <label><?php echo $eUserLastname ?></label>
            </p>
            <p>
                <label>Username:</label>
                <label><?php echo $eUserUsername ?></label>
            </p>
            <p>
                <label>Email Address:</label>
                <label><?php echo $eUserEmail ?></label>
            </p>
            <p>
                <label>User Company:</label>
                <label><?php echo $eUserCompany ?></label>
            </p>
            <p>
                <label>Set Company:</label>
                <select name="setCompany">
                    <option><?php echo $companyValue ?></option>
                    <?php
                    foreach ($setCompany as $srow)
                    {
                        ?>
                        <option id="<?=
                        $srow->company_id
                        ?>">
                            <?=
                            $srow->company_name
                            ?>
                        </option>
                        <?php
                    }
                    ?>
                </select>
            </p>
            <p>
                <label>Administrator:</label>
                <select name="userAdmin">
                    <option><?php echo $userAdmin ?></option>
                    <?php
                    foreach ($adminArray as $arow)
                    {
                        ?>
                        <option>
                            <?=
                            $arow
                            ?>
                        </option>
                        <?php
                    }
                    ?>
                </select>
            </p>
            <input type="submit" name="cancel" value="Cancel">
            <input type="submit" name="confirm" value="Confirm">
            </br>
        </form>


名字:

姓氏:

用户名:

电邮地址:

用户公司:

Set公司:
将第一个表单提交的内容存储在echo语句旁边的隐藏输入字段中。例如:
如果它是隐藏的,用户将如何确认?您仍然会回显内容。我明白了。。问题是针对op的,
阻止用户更改任何值,如果用户结婚后的姓氏需要更改怎么办?这不符合要求。此外,您可以在文本字段中显示内容,而不是隐藏,以便他们在必要时可以编辑。@HalfCrazed我会尝试一下,谢谢。作为信息,这只是为了让管理员更新用户可以访问的网站部分,如果需要,用户可以自己编辑其他字段。