0

Hi,
Please look at this:

<?php
 
print '
<form>
 <td><input type="text" name="txt" maxlength="7" style="text-transform:uppercase"></td>
</form>
</html>';

if(isset($_POST['submit'])
{
  $val=$_POST['txt'];
#header();
}
 ?>

my text box values gets erased after submit button. If i use header function:
error is
Warning: Cannot modify header information - headers already sent by (output started at C:\xampplite\htdocs\test.php:8) in C:\xampplite\htdocs\test.php on line 113

I want this format of my php coding. Please give me a solution to retain my text box values.

3
Contributors
13
Replies
31
Views
6 Years
Discussion Span
Last Post by jacksantho
0

You don't have a submit button from what I can see, so how are you submitting?
Also POST won't work as you don't stipulate a method attribute in the form tag. By default form method is GET. I don't understand the closing </html> tag. It doens't seem to make much sense to place it there. No DTD, No head, no BODY or is this script an include file?
The header() function although commented out, does not have any attributes so it won't do anything useful. The header() needs to be placed before any output (any html or echoed stuff from php).

All in all, you need to check some html and php tutorials on how to provide valid markup and create forms and how to process form data (it's also good practice to send form data to a different page via the action attribute).

0

Your code haven't got sense.
First your check must be at start of your code so your PHP to work depnding if the event is happened or not.
Other thing is that you must add method="post" to your form.
And after ($_POST) you have missed one ).
One more thing you must make a submit button if you want to use $_POST for check

Here is corrected code sample:

<?php

    if(isset($_POST['submit']))
    {
    $val=$_POST['txt'];
    #header();
	echo $val;
    }     
    print '
    <form method="post">
    <td><input type="text" name="txt" maxlength="7" style="text-transform:uppercase"></td>
    <td><input type="submit" name="submit" maxlength="7" style="text-transform:uppercase" value="submit"></td>
    </form>
    </html>';
     
    ?>

I have added one echo of the posted text to see that its working.

Edited by sv3tli0: n/a

0

My previous code is the sample code.

<?php

print '<html>

<body bgcolor=#FF8C00>
<table align=center>
<tr><th>Form</th></tr>
</table>

<table align="center" border="1">
  <tr><th>Sno</th><th>Item</th></tr>
  <form method="post" name="f1">
  <tr>
  <td>1</td>
  <td><input type="text" name="txt" maxlength="7" style="text-transform:uppercase"></td>
  </tr>

<tr>
 <td colspan="3" align="center"><input type="submit" name="submit" value="submit"></td>
 </tr>
 </form>
 </table>
 
 </body>
 </html>';
 if(isset($_POST['submit']) && ($_POST['submit'])=="submit")
{
	$val=trim($_POST['txt']);
}
?>

I am not facing the error. I need text box values to be retained. I dont know.

0

Hi,

I need my isset function at the bottom of the page only. Because i am displaying the result on the same page at the bottom of the form.

0
if(isset($_POST['submit']) && ($_POST['submit'])=="submit"){
   $val=trim($_POST['txt']);
}else{
   $val="";
}

that at top of file, then:

<td><input type="text" name="txt" maxlength="7" value="<?php echo $val;?>" style="text-transform:uppercase" /></td>
0
if(isset($_POST['submit']) && ($_POST['submit'])=="submit")
    {
    $val=trim($_POST['txt']);
	print $val;
    }

just add one print and you will get your content.
If you want to store it you will need some kind of database (mysql or other) or other type for storing your data.

0

hi,
thanks for your coding

<td><input type="text" name="txt" maxlength="7" value="<?php echo $val;?>" style="text-transform:uppercase" /></td>

when i try your code, again the problem,

in my text box, i am getting like this <?php echo $val;?>.

I am not getting it correctly.

0

try

<td><input type="text" name="txt" maxlength="7" value="'.$val.'" style="text-transform:uppercase" /></td>

he hasnt notice that you use var for your html code

0

No, its not working.

click on submit button "textbox value gets erased". Please check my code..what i posted.

0
<?php
     $val="";
    if(isset($_POST['submit']) && ($_POST['submit'])=="submit")
    {
    $val=trim($_POST['txt']);
    }
    print '<html>
     
    <body bgcolor=#FF8C00>
    <table align=center>
    <tr><th>Form</th></tr>
    </table>
     
    <table align="center" border="1">
    <tr><th>Sno</th><th>Item</th></tr>
    <form method="post" name="f1">
    <tr>
    <td>1</td>
    <td><input type="text" name="txt" maxlength="7" style="text-transform:uppercase" value="'.$val.'"></td>
    </tr>
     
    <tr>
    <td colspan="3" align="center"><input type="submit" name="submit" value="submit"></td>
    </tr>
    </form>
    </table>
     
    </body>
    </html>';
    ?>

Tested..

0

hi..i know it will work. but my isset() function i need at the bottom of my html tag. Because i am displaying my result set at the botton of the form text box.

if i placed isset() function at the top of the page means, my result set displayed at the top of my textbox. It won't looks good for me. So i am placing isset() function at the bottom of the page. thanks

0
<?php
     
    print '<html>
     
    <body bgcolor=#FF8C00>
    <table align=center>
    <tr><th>Form</th></tr>
    </table>
     
    <table align="center" border="1">
    <tr><th>Sno</th><th>Item</th></tr>
    <form method="post" name="f1">
    <tr>
    <td>1</td>
    <td><input type="text" name="txt" maxlength="7" style="text-transform:uppercase" value="'.trim($_POST['txt']).'"></td>
    </tr>
     
    <tr>
    <td colspan="3" align="center"><input type="submit" name="submit" value="submit"></td>
    </tr>
    </form>
    </table>
     
    </body>
    </html>';
    if(isset($_POST['submit']) && ($_POST['submit'])=="submit")
    {
    $val=trim($_POST['txt']);
    }
    ?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.