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

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

<?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 !

I assume the page gets refreshed when you submit (ie, it isn’t submitted via JavaScript)?

If so, all your form data is in the $_POST object, so you can do something like:

$value = array_key_exists('myEMP', $_POST) ? htmlspecialchars($_POST['myEMP']) : '';

echo <<<_END
<FORM action = "abc.php" method = "POST">
Employer    <INPUT TYPE = "number" name = "myEMP" value="$value">
            <input type = "submit" value = "ADD SHIFT">
</FORM>
_END;
2 Likes

Thank you very much !

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.