开发者

Passing values in form Box

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:<开发者_Python百科/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?


<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.


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']); ?>">


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'])); ?>'>

?


<?php $htmlvalue= htmlspecialchars($_GET['title']); ?>

before the textbox element

<input type="text" name="title" size="50" value="<?php echo htmlvalue; ?>"/>


Use the same form, except add a value attribute.

for instance

<input type="text" name="title" size="50" value="<?php echo($value); ?>"/>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜