473,372 Members | 1,682 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

how can inputed value display on a textfield

123 100+
i want an inputed value that a user enter into the textfield
should remain after clicking submit and an error message display
that invalued email.the email textfield will be blank why the other
textfield will still display the inputed value
May 9 '09 #1
6 4048
Markus
6,050 Expert 4TB
The data will be available in the GET or POST array once the form has been submitted. Therefore, you can set the value of an input field to the data from your GET or POST array (if it exists).

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. function get_value($key, $default = '') {
  3.     if (isset($_POST[$key]) {
  4.         return $_POST[$key];
  5.     }
  6.     return $default;
  7. }
  8. ?>
  9. <input type="text" name="my_input" value="<?php echo get_value('my_input', 'default text');?>" />
  10.  
You could expand the helper function to include GET and COOKIE and SESSION if you liked. You could even use $_REQUEST.
May 9 '09 #2
simon2x1
123 100+
i have try the code but is give me an error where my input field his also how can do the same for the other field i will appreciate if you made the adjustment on my code
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. if (isset($_POST['submit'])) {
  4.  
  5. $firstname = ($_POST['firstname']);
  6.  $lastname = ($_POST['lastname']);
  7. $email = ($_POST['email']);
  8.  
  9. function get_value($fname, $default = '') {
  10.    if (isset($_POST[$fname])) {
  11.          return $_POST[$fname];
  12.      }
  13.      return $default;
  14.          }
  15.  
  16. mysql_query("INSERT INTO USER (firstname, lastname, email) VALUES
  17. ('" . $firstname . "', '" . $lastname . "', '" . $email . "')") or die(mysql_error());
  18.  
  19. <form  method="post" action="home.php">
  20. <input type="text" name="firstname" value="<?php echo get_value('fname','firstname');?> />
  21. <input type="text" name="lastname"  />
  22. <input type="text" name="email"  />
  23. <input type="submit" name="submit"  />
  24. </form>
  25.  
May 12 '09 #3
simon2x1
123 100+
i have try the code but is give me an error where my input field his also how can do the same for the other field i will appreciate if you made the adjustment on my code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (isset($_POST['submit'])) {
  3.  
  4. $firstname = ($_POST['firstname']);
  5.  $lastname = ($_POST['lastname']);
  6. $email = ($_POST['email']);
  7.  
  8. function get_value($fname, $default = '') {
  9.    if (isset($_POST[$fname])) {
  10.          return $_POST[$fname];
  11.      }
  12.      return $default;
  13.          }
  14.  
  15. mysql_query("INSERT INTO USER (firstname, lastname, email) VALUES
  16. ('" . $firstname . "', '" . $lastname . "', '" . $email . "')") or die(mysql_error());
  17.  
  18. <form  method="post" action="home.php">
  19. <input type="text" name="firstname" value="<?php echo get_value('fname','firstname');?> />
  20. <input type="text" name="lastname"  />
  21. <input type="text" name="email"  />
  22. <input type="submit" name="submit"  />
  23. </form>
  24.  
May 12 '09 #4
dlite922
1,584 Expert 1GB
What does the error say? Usually Errors tell you what's wrong.




@simon2x1
May 13 '09 #5
simon2x1
123 100+
sorry what i mean by error is that it do not work pls help me check my code and see what i do wrong
May 14 '09 #6
hoopy
88
It does not look like you are closing your IF statement and also have HTML embedded in the PHP which in turn has this embedded in it:

<?php echo get_value('fname','firstname');?> />

Simply saying "It doesnt work" does not help, give the errors which PHP has given to you.

Try this code which is a cleaned up version of your existing version:

Expand|Select|Wrap|Line Numbers
  1. <?
  2. function get_value($fname, $default = '') {
  3.   if (isset($_POST[$fname])) {
  4.   return $_POST[$fname];
  5.   }
  6.   return $default;
  7. }
  8.  
  9. if(isset($_POST['submit'])) 
  10. {
  11.   $firstname = $_POST['firstname'];
  12.   $lastname = $_POST['lastname'];
  13.   $email = $_POST['email'];
  14.  
  15.   mysql_query("
  16.     INSERT INTO USER (firstname, lastname, email) VALUES
  17.     ('" . $firstname . "', '" . $lastname . "', '" . $email . "')
  18.   ") or die(mysql_error());
  19. }
  20. ?>
  21.  
  22. <form  method="post" action="home.php">
  23. <input type="text" name="firstname" value="<?php echo get_value('fname','firstname');?> />
  24. <input type="text" name="lastname"  />
  25. <input type="text" name="email"  />
  26. <input type="submit" name="submit"  />
  27. </form>
May 14 '09 #7

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

Similar topics

1
by: LRW | last post by:
Below is some of the code I'm using. I have a PHP page generating a list of items. I've made it so that each one has a radiobutton with a unique value. You can click on the radiobutton and it will...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
14
by: TonyK | last post by:
Hello fellow Access-users, I am struggling with the following problem: I have a Table wich has an id, code and name of a person I would like to insert records in another Table called History...
0
by: vidhyasreddy | last post by:
Hi All, While we are Localizing our product we faced below problem: java.awt components not able to display some non-english charecters like \u2019 , \u2018 , \u2026 , \u2013 , \u8230 . ...
5
by: pradeep84 | last post by:
Hi.. to all... in the following program i hav retrived data from the database and stored in the string s2,s3... now i hav display the following string in the textfields... i dont know how.. to do...
1
by: macintoshhondo | last post by:
Hi ! i am a newbie and dont know javascript much. what i really need is a simple javascript code that can insert number in the value section of the different forms from the one form. FORM 1:...
1
by: prathna | last post by:
Hi all, I would like to know how to pass a form bean value to javascript function to perform some validation.. I have a dropdown list and a textfield. I have created the dropdown list using...
5
by: xirowei | last post by:
public class Result { private int countA = 0; private int countB = 0; private int statement; private boolean statusA = false; private boolean statusB = false; private int arrayA = new...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.