PHP 的问题;发布隐藏价值?

发布于 2024-08-24 18:34:52 字数 1874 浏览 2 评论 0原文

我有一个页面,基本上允许管理员用户创建管理员用户类型(基本上是一个注册函数)。因此,当提交值时,它们会存储到数据库中,非常非常基本的东西。但是,我有一个隐藏的变量类型。原因是我有 3 个不同的用户级别,并且我已将它们声明为整数(例如 7 = 经理,8 = 用户等)。

有人可以帮助我如何正确传递这个隐藏值,以便将其存储在数据库中。 我基本上试图仅针对此

这是我的表单:

<form id="userreg" name="userreg" method="post" action="adduser-process.php"> 
<label>Full Name:</label> <input name="fullname" size="40" id="fullname" value="<?php if (isset($_POST['fullname'])); ?>"/>
    <br />
    <label>Username:</label> <input name="username" size="40" id="username" value="<?php if (isset($_POST['username'])); ?>"/>       <br />
    <label>Password:</label> <input name="password" size="40" id="password" value="<?php if (isset($_POST['password'])); ?>"/>        <br />
    <label>Email Address:</label> <input name="emailaddress" size="40" id="emailaddress" value="<?php if (isset($_POST['emailaddress'])); ?>"/> 
    <br />
    <input name="userlevel" type="hidden" size="1" id="userlevel" value="<?php $_POST[5]; ?>" /> <br />
    <input value="Add User" class="addbtn" type="submit" /> 
    </form></div>

接下来,这是运行查询的脚本:

    <?php 

require_once "config.php";


 $fullname = $_POST['fullname'];
 $username = $_POST['username'];
 $password = $_POST['password'];
 $emailaddress = $_POST['emailaddress'];
 $userlevel = $_POST[5];


 $sql = "INSERT INTO users_tb VALUES('".$user_id."','".$fullname."','".$username."',MD5('".$password."'),'".$emailaddress."','".$userlevel."')";
 $result = mysql_query($sql, $connection)
  or die("MySQL Error: ".mysql_error());

 header("Location: administratorfrontview.php");
 exit();
 ?>  

表单传递带有常量值“5”的隐藏 typem,因为它不会更改...当我在这里时,由于某种原因,“全名”也没有存储在数据库中!?所有其他字段都处理得很好,非常感谢!

I have a page which basically allows an admin user to create manager user types (basically a register function. So when the values are submitted, they are stored into the DB, very very basic stuff. However, I have a hidden variable type..reasons are I have 3 different user levels and I have declared they identification as an integer (e.g. 7 = manager, 8 =user etc.)

Can someone help me out with how to correctly pass this hidden value so it stores in the database...

Here is my form:

<form id="userreg" name="userreg" method="post" action="adduser-process.php"> 
<label>Full Name:</label> <input name="fullname" size="40" id="fullname" value="<?php if (isset($_POST['fullname'])); ?>"/>
    <br />
    <label>Username:</label> <input name="username" size="40" id="username" value="<?php if (isset($_POST['username'])); ?>"/>       <br />
    <label>Password:</label> <input name="password" size="40" id="password" value="<?php if (isset($_POST['password'])); ?>"/>        <br />
    <label>Email Address:</label> <input name="emailaddress" size="40" id="emailaddress" value="<?php if (isset($_POST['emailaddress'])); ?>"/> 
    <br />
    <input name="userlevel" type="hidden" size="1" id="userlevel" value="<?php $_POST[5]; ?>" /> <br />
    <input value="Add User" class="addbtn" type="submit" /> 
    </form></div>

Next, here is the script that runs the query:

    <?php 

require_once "config.php";


 $fullname = $_POST['fullname'];
 $username = $_POST['username'];
 $password = $_POST['password'];
 $emailaddress = $_POST['emailaddress'];
 $userlevel = $_POST[5];


 $sql = "INSERT INTO users_tb VALUES('".$user_id."','".$fullname."','".$username."',MD5('".$password."'),'".$emailaddress."','".$userlevel."')";
 $result = mysql_query($sql, $connection)
  or die("MySQL Error: ".mysql_error());

 header("Location: administratorfrontview.php");
 exit();
 ?>  

I'm basically trying to pass the hidden typem with a constant value of '5' just for this form, as it will not be changed...also while im here, for some reason, the 'fullname' is not stored in the DB either!!?? WTH?? all other fields are processed fine. Any help is much appreciated! Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

总以为 2024-08-31 18:34:52

有两件事。第一,$userlevel 应等于 $_POST['userlevel'] 而不是 5,因为 POST 数据并不总是按此顺序排列。第二,插入语句前面应该带有列名(以防止任何数据以错误的顺序排列)。

$sql = "INSERT INFO users_tb (id, name, username, password, email, userlevel) ".
       "('".$user_id."','".$fullname."','".$username."',MD5('".$password."'),'".
       $emailaddress."','".$userlevel."')";

Two things. One, $userlevel should equal $_POST['userlevel'] not 5 as POST data isn't always in that order. Two, your insert statement should be preceded with the column names (to prevent any data from going in the wrong order).

$sql = "INSERT INFO users_tb (id, name, username, password, email, userlevel) ".
       "('".$user_id."','".$fullname."','".$username."',MD5('".$password."'),'".
       $emailaddress."','".$userlevel."')";
拥抱没勇气 2024-08-31 18:34:52

你的 PHP 输出值是错误的。使用:

<?= $_POST[5]; ?>

<?php echo $_POST[5]; ?>

Your PHP for outputting the value is wrong. Use:

<?= $_POST[5]; ?>

or

<?php echo $_POST[5]; ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文