How I insert hidden field in database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hemaldazzle
    New Member
    • Jul 2012
    • 15

    How I insert hidden field in database?

    Code:
     <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" name="form1">
                	<table width="69%" border="0" align="center">
      
      <tr>
        <td width="25%">Date</td>
        <td width="75%"><input name="date" type="text" size="40" id="date" value="<?php echo date("Y-m-d")?>" ></td>
      </tr>
      <tr>
        <td>Hours</td>
        <td><input name="hours" type="text" size="40" id="hours"></td>
      </tr>
      
       
    
      <tr>
        <td>Work Details</td>
        <td><textarea name="work" cols="22" rows="4" id="work"></textarea></td>
        <input name="memberid" type="hidden" size="40" value="<?php echo $myusername; ?>">
      </tr>
      <tr>
        <td colspan="2" align="center"><input name="submit" type="submit"></td>
       
      </tr>
      
    </table>
    </form>
    <?php 
    if(isset($_POST['submit']))
    {
    	$date=$_POST['date'];
    	$hours=$_POST['hours'];
    	$work=$_POST['work'];
    	
    	
    	
    	mysql_connect("localhost","root","") or die(mysql_error());
    	mysql_select_db("secure_login")or die(mysql_error());
    	
    	$insert="INSERT into member_details(date,hours,message,member_name) values('$date','$hours','$work',$myusername)";
    	$result=mysql_query($insert);
    	if($result)
    	{
    		echo "Insert the data";	
    	}
    	else
    	{
    		echo "not insert data ..." .mysql_error();	
    	}
    	
    	
    	}
    	else
    	{
    		echo "<script> alert('Enter the all fields');</script>";
    		
    	}
    
    
    ?>
                
                
    </body>
    </html>
  • lyodmichael
    New Member
    • Jul 2012
    • 75

    #2
    hmm, you are trying to save this? $myusername; right? then use it .

    like
    Code:
    $query = "INSERT INTO table (
    Field
    ) 
    VALUES
    (
    '{$myusername}')";

    Comment

    • deric
      New Member
      • Dec 2007
      • 92

      #3
      Get the value of the hidden field the same way as you get the values for other fields...
      Code:
      $myusername=$_POST['memberid'];

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        but the problem is that $myusername must be already present in the PHP file to be put in the hidden form field.

        and since the same file is responsible for output and DB action, there is no reason to fetch the username from the form data. $myusername already exists in the script! (and if it doesn’t, it wouldn’t in the form either)
        Last edited by Dormilich; Aug 3 '12, 08:45 AM.

        Comment

        Working...