473,503 Members | 12,791 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 3577
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
3679
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...
8
4250
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 =...
3
2184
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...
2
4226
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"...
4
3612
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...
4
1727
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...
5
2745
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...
8
18794
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>...
3
1549
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...
5
4226
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...
0
7212
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,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7296
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,...
0
7364
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...
0
7470
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...
0
3186
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...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.