473,569 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How I insert hidden field in database?

15 New Member
Expand|Select|Wrap|Line Numbers
  1.  <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" name="form1">
  2.                 <table width="69%" border="0" align="center">
  3.  
  4.   <tr>
  5.     <td width="25%">Date</td>
  6.     <td width="75%"><input name="date" type="text" size="40" id="date" value="<?php echo date("Y-m-d")?>" ></td>
  7.   </tr>
  8.   <tr>
  9.     <td>Hours</td>
  10.     <td><input name="hours" type="text" size="40" id="hours"></td>
  11.   </tr>
  12.  
  13.  
  14.  
  15.   <tr>
  16.     <td>Work Details</td>
  17.     <td><textarea name="work" cols="22" rows="4" id="work"></textarea></td>
  18.     <input name="memberid" type="hidden" size="40" value="<?php echo $myusername; ?>">
  19.   </tr>
  20.   <tr>
  21.     <td colspan="2" align="center"><input name="submit" type="submit"></td>
  22.  
  23.   </tr>
  24.  
  25. </table>
  26. </form>
  27. <?php 
  28. if(isset($_POST['submit']))
  29. {
  30.     $date=$_POST['date'];
  31.     $hours=$_POST['hours'];
  32.     $work=$_POST['work'];
  33.  
  34.  
  35.  
  36.     mysql_connect("localhost","root","") or die(mysql_error());
  37.     mysql_select_db("secure_login")or die(mysql_error());
  38.  
  39.     $insert="INSERT into member_details(date,hours,message,member_name) values('$date','$hours','$work',$myusername)";
  40.     $result=mysql_query($insert);
  41.     if($result)
  42.     {
  43.         echo "Insert the data";    
  44.     }
  45.     else
  46.     {
  47.         echo "not insert data ..." .mysql_error();    
  48.     }
  49.  
  50.  
  51.     }
  52.     else
  53.     {
  54.         echo "<script> alert('Enter the all fields');</script>";
  55.  
  56.     }
  57.  
  58.  
  59. ?>
  60.  
  61.  
  62. </body>
  63. </html>
Aug 1 '12 #1
3 3587
lyodmichael
75 New Member
hmm, you are trying to save this? $myusername; right? then use it .

like
Expand|Select|Wrap|Line Numbers
  1. $query = "INSERT INTO table (
  2. Field
  3. VALUES
  4. (
  5. '{$myusername}')";
Aug 1 '12 #2
deric
92 New Member
Get the value of the hidden field the same way as you get the values for other fields...
Expand|Select|Wrap|Line Numbers
  1. $myusername=$_POST['memberid'];
Aug 3 '12 #3
Dormilich
8,658 Recognized Expert Moderator Expert
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)
Aug 3 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
3690
by: Randell D. | last post by:
Folks, Perhaps someone can figure this out - this is 'the process of my script' I have a form whereby I can add multiple contacts to a single address. There is only one firstname/lastname/telephone box - when the user clicks the add button, I read the values from the form fields and record them into a hidden text input field. This part...
8
4254
by: Tom Petersen | last post by:
Here is the code: <SELECT NAME="email" style="font-family: Verdana; font-size: 10pt; " size="1"> <% DO WHILE NOT objRS.EOF strEmail = objRS("email") strLName = objRS("last_name") strFName = objRS("first_name") %> <option value="<% =strEmail %>"><%= strLName & ", " & strFName %>
3
2191
by: Roy Adams | last post by:
Hi I'm reposting this question because for some reason can't post follow up question to this thread. What I'm trying to do is put the value and text from a a select in to a text field and to a hidden field respectfully and the value from dynamically created hidden fiields in to a text fieldin to a text field all at the same time Here's...
2
4233
by: Rodusa | last post by:
I have a hidden field inside one datagrid which I can't get to make it keep its state after a postback event. Look field: <input type="hidden" id="TxtHiddenItem_id" name="TxtHiddenItem_id" runat="server" value='<%# DataBinder.Eval(Container, "DataItem.item_id").ToString() %>'> I can get around that using an asp.net textbox control, but...
4
3620
by: Magnus Blomberg | last post by:
Hello! I have a problem when using a hidden field to send a value to the server. Below you can see my code in simplyfied versions. What I'm trying to do is: 1. The user browses for a picture at the network from their computer using control File1. 2. The user clickes the button Commit picture (with id CliBtn) a. The script is running at...
4
1733
by: Joe | last post by:
Hello All: I have two webforms (WebForm1.aspx and WebForm2.aspx) that inherit from a base class called BasePage.aspx. BasePage.aspx has no user interface but inherits System.Web.UI.Page (BasePage performs security checks in the Page_Load ... Handles MyBase.Load event). BasePage also has a hidden field (hdnSessionId) that I want to use to...
5
2751
by: dvwool | last post by:
Hello, Another newbie here... I've been trying to make this work for days now and have finally decided to post as I can't seem to get it to work. Here's what I'm trying to do... I have a select box with three options and a separate hidden field. The value of a hidden field is dependent upon which of the three options is selected. For...
8
18804
by: =?Utf-8?B?cGVsZWdrMQ==?= | last post by:
i have a GridView and a hidden field : <asp:TemplateField Visible=false > <ItemTemplate > <asp:HiddenField Value="<%#Eval("isActive")%>" id="hidIsActive" runat=server /> </ItemTemplate> </asp:TemplateField> 1)when i check the sorce of html i dont see the hidden field - why is that? 2)on RowDataBound event, when i check the rows i want to...
3
1556
by: Chrisdude | last post by:
Hello again everyone. This should be very simple for you guys. I have 2 controls on an insert item template. One is a dropdownlist, the other is a hidden field. The dropdownlist autopostback is enabled. My question is, How do I insert data from the dropdown list when a value is selected? One important thing is the hidden field is bound to an...
5
4230
by: laredotornado | last post by:
Hi, Is there a way to trigger an event when the value of a hidden field changes? At a certain point in time my hidden field is getting changed to a value that I don't want but I can't find a place in the code where this is happening by doing a search for its variable name. Thanks, - Dave
0
7700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7974
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.