Reputation: 109
I got some values from a previous PHP file
EX:
<?php
$value = $_GET['title'];
$value1 = $_GET['name'];
$value2 = $_GET['age'];
$value3 = $_GET['institution'];
?>
Now i have a form field like following
<body>
<form action="pare.php" method="post">
<label>Title:</label>
<input type="text" name="title" size="50"/><br/>
<label>Name:</label>
<input type="text" name="name" size="50"/><br/>
<label>age:</label>
<input type="text" name="age" size="50"/> <br/>
<label>Institution:</label>
<select name="institution">
<option value="">-- Select --</option>
<option value="abc">abc</option>
</select><br/>
<label></label>
<input type="submit" value="submit" /><br/>
</form>
</body>
Now what i want to do is display the values in a PHP file($value,$value1...)in their respective form field boxes.
If the user wants to edit those values($value,$value1...) he must be able to edit and submit those values.
how can i do this?
Upvotes: 1
Views: 131
Reputation: 220
<?php $htmlvalue= htmlspecialchars($_GET['title']); ?>
before the textbox element
<input type="text" name="title" size="50" value="<?php echo htmlvalue; ?>"/>
Upvotes: 0
Reputation: 1258
Use the same form, except add a value attribute.
for instance
<input type="text" name="title" size="50" value="<?php echo($value); ?>"/>
Upvotes: -1
Reputation: 8767
I assume you are wanting to replace the null value
attribute with the value obtained from your PHP code. In that event, you will want to simply add the value
attribute and set it to the desired PHP variable:
<input type="text" name="name" value="<?php echo htmlspecialchars($_GET['nameVar']); ?>">
Upvotes: 1
Reputation: 24661
I think I understand your question correctly, and if I do why not just set the value
attribute on your inputs?
<input type = 'text' name = 'name' size = '50' value = '<?php echo(htmlspecialchars($_GET['name'])); ?>'>
?
Upvotes: 0
Reputation: 360702
<input type="text" name="title" value="<?php echo htmlspecialchars($_GET['title']) ?> />
note the use of htmlspecialchars. It prevents any HTML metacharacters ("
in particular) within the data from 'breaking' your form - e.g... it prevents HTML injection attacks.
Upvotes: 2