×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How do I display "input" value of form at its' box ?

How do I display "input" value of form at its' box ?

How do I display "input" value of form at its' box ?

(OP)
Hello everyone,
Attached is a PHP code to assign data into an HTML form:

CODE -->

<?php // abc.php
$MyHOST = 'localhost';
$MyUSER = 'user';
$MyPASS = 'pass';
$MyDB = 'test';
$MyCONNECTION = NEW MYSQLI($MyHOST,$MyUSER,$MyPASS,$MyDB);
IF(!$MyCONNECTION)
DIE('Gevald' .MYSQLI_CONNECT_ERROR());
MYSQLI_SET_CHARSET($MyCONNECTION,'UTF8');

IF (ISSET($_POST['myEMP']))
{
	$yosEmp = get_post($MyCONNECTION,'myEMP');

	$MyQUE = "INSERT INTO hourShifts (employer) VALUES($yosEmp)";
	$MyRESULT = $MyCONNECTION->query($MyQUE);
	if (!$MyRESULT) echo "INSERT failed: $MyQUE<br>" . $MyCONNECTION->error . "<br><br>";
}
ELSE ECHO $MyCONNECTION->error;
echo <<<_END
<FORM action = "abc.php" method = "POST">
Employer    <INPUT TYPE = "number" name = "myEMP">
			<input type = "submit" value = "ADD SHIFT">
</FORM>
_END;

function get_post($MyCONNECTION, $var)
{
return $MyCONNECTION->real_escape_string($_POST[$var]);
}
?> 
Once I push the "submit" yhe value entered goes to a MySQL table and vanishs from the display.
I'd like the value entered to remain for further process like editing or delete.
How do I make an input box value to remain on the display?
Thanks !

RE: How do I display "input" value of form at its' box ?

You have

CODE

<?php // abc.php
$MyHOST = 'localhost';
$MyUSER = 'user';
$MyPASS = 'pass';
$MyDB = 'test';
$MyCONNECTION = NEW MYSQLI($MyHOST,$MyUSER,$MyPASS,$MyDB);
IF(!$MyCONNECTION)
DIE('Gevald' .MYSQLI_CONNECT_ERROR());
MYSQLI_SET_CHARSET($MyCONNECTION,'UTF8');

IF (ISSET($_POST['myEMP']))
{
	$yosEmp = get_post($MyCONNECTION,'myEMP');

	$MyQUE = "INSERT INTO hourShifts (employer) VALUES($yosEmp)";
	$MyRESULT = $MyCONNECTION->query($MyQUE);
	if (!$MyRESULT) echo "INSERT failed: $MyQUE<br>" . $MyCONNECTION->error . "<br><br>";
}
ELSE ECHO $MyCONNECTION->error;
echo <<<_END
<FORM action = "abc.php" method = "POST">
Employer    <INPUT TYPE = "number" name = "myEMP">
			<input type = "submit" value = "ADD SHIFT">
</FORM>
_END;

function get_post($MyCONNECTION, $var)
{
return $MyCONNECTION->real_escape_string($_POST[$var]);
}
?> 
I prefer

CODE

<?php // abc.php
$MyHOST = 'localhost';
$MyUSER = 'user';
$MyPASS = 'pass';
$MyDB = 'test';
$MyCONNECTION = NEW MYSQLI($MyHOST,$MyUSER,$MyPASS,$MyDB);
IF(!$MyCONNECTION)
DIE('Gevald' .MYSQLI_CONNECT_ERROR());
MYSQLI_SET_CHARSET($MyCONNECTION,'UTF8');

IF (ISSET($_POST['myEMP']))
{
	$yosEmp = get_post($MyCONNECTION,'myEMP');

	$MyQUE = "INSERT INTO hourShifts (employer) VALUES($yosEmp)";
	$MyRESULT = $MyCONNECTION->query($MyQUE);
	if (!$MyRESULT) echo "INSERT failed: $MyQUE<br>" . $MyCONNECTION->error . "<br><br>";
} ELSE { ECHO $MyCONNECTION->error; }
function get_post($MyCONNECTION, $var)
{
return $MyCONNECTION->real_escape_string($_POST[$var]);
}
?> 
<FORM action = "abc.php" method = "POST">
Employer<br />
<INPUT TYPE = "number" name = "myEMP" value="<?php echo (isset($_POST['myEMP'])?$_POST['myEMP']:''); ?>">
<input type = "submit" value = "ADD SHIFT">
</FORM> 
Of course, this does not address injection issues but it points you in the direction of retaining values ...

--
SouthBeach
http://www.fp2php.com
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.

RE: How do I display "input" value of form at its' box ?

(OP)
Thanks a lot southbeach, you were very helpful !

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close