如何使用php将隐藏字段数据插入数据库

问题描述:

当我登录网站时,iam在登录后填写表格时在隐藏字段中获取用户名,但我需要在数据库中插入用户名.但是iam获取错误为

Hi While login into the site iam getting the username in hidden field while filling the form after login i need to insert the username in database.But iam getting The error as

注意:未定义索引:电子邮件

Notice: Undefined index: email

这是我的代码

index.php

index.php

<?php  
$username = $_SESSION['username'];
if($username) 
{ 
?>
<h3> Welcome <?php echo $username; ?></h3>
<?php 
}  
else 
{ 
echo "no"; 
} 
?> 
<body>       
    <input type='hidden' value="<?php echo $username; ?>" name='email'>        
    <input type="button" value="Logout" id="logout" onClick="document.location.href='login.php'" />    
    <form method="post" action="details.php" id="myform">            
        <ul class="tab-content">
                <li class="tab-pane active" id="salary">                
                            <h3>Details</h3>
                            <table style="border-collapse: collapse;border: 1px solid black;">
                            <tr class="spaces">
                              <th>User Name</th></tr>
                              <tr>
                              <td><input type="text" name="user_name" value="" required /></td>
                              </tr>

details.php

details.php

<?php
$connection = mysql_connect("localhost", "root", "") or die(mysql_error());
$db = mysql_select_db("accountant", $connection);
$email=$_POST['email'];
$name=$_POST['user_name'];
$query=mysql_query("INSERT INTO user_details(email,user_name)values('$email','$name')");

任何人都可以提前谢谢我吗

Can anyone help me this thanks in advance

在填写此表单时,我还需要在数据库中插入隐藏字段值

While filling this form i need to insert the hidden field value also in database

尝试将该字段放入表单标签中,您就完成了.

Try putting that field in form tag and you done.

<?php
    $username = $_SESSION['username'];
    if($username){?>
        <h3> Welcome <?php echo $username; ?></h3>
    <?php } else {
        echo "no";
    }
?>
<body>
    <input type="button" value="Logout" id="logout" onClick="document.location.href='login.php'" />
    <form method="post" action="details.php" id="myform">
        <input type='hidden' value="<?php echo $username; ?>" name='email'>
        <ul class="tab-content">
            <li class="tab-pane active" id="salary">
                <h3>Details</h3>
                <table style="border-collapse: collapse;border: 1px solid black;">
                    <tr class="spaces">
                        <th>User Name</th>
                    </tr>
                    <tr>
                        <td>
                            <input type="text" name="user_name" value="" required />
                        </td>
                    </tr>