Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

lupidol

Programmer
Apr 23, 2008
125
IL
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 !
 
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
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Thanks a lot southbeach, you were very helpful !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top