开发者

Load Returned mySQL Values Into Form

I wonder whether someone may be able to help me please.

I've put together a form and php code (below) that allows an administrator to search for member records from a mysql database using the email address as the search criteria.

HTML Form

   <form name="memberpasswordresetform" id="memberpassword开发者_StackOverflow中文版resetform" method="post" action="search.php">
    <div class="container">
        <p align="justify">Member Details </p>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td width="26%" height="25"><strong>Email Address </strong></td>
                <td width="4%">&nbsp;</td>
                <td width="70%"><input name="email" type="email" id="email" size="50" /></td>
            </tr>
            <tr>
                <td height="25"><strong>Confirm Email Address </strong></td>
                <td>&nbsp;</td>
                <td><input name="conf_email" type="email" id="conf_email" size="50" /></td>
            </tr>
            <tr>
                <td height="25"><label>
                    <input type="submit" name="Submit" value="search" />
                    </label></td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td height="25">&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>

            <tr>
                <td height="25"><strong>First Name </strong></td>
                <td>&nbsp;</td>
                <td><input name="fname" type="text" id="fname" size="30" /></td>
            </tr>
            <tr>
                <td height="25"><strong>Last Name </strong></td>
                <td>&nbsp;</td>
                <td><input name="lname" type="text" id="lname" size="30" /></td>
            </tr>
            <tr>
                <td height="25">&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td height="25"><strong>New Password</strong></td>
                <td>&nbsp;</td>
                <td><input name="newpass" type="password" id="newpass" size="30" /></td>
            </tr>
            <tr>
                <td height="25"><strong>Confirm New Password </strong></td>
                <td>&nbsp;</td>
                <td><input name="conf_newpass" type="password" id="conf_newpass" size="30" /></td>
            </tr>
            <tr>
                <td height="25"><input type="submit" name="save" value="save" /></td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
        </table>
    </div>
</form>

PHP Script

<?php 
include("admin/link.php");
include("admin/opendb.php");
mysql_select_db ("userdetails"); 
$term = $_POST['email']; 
$sql = mysql_query("select forename, surname, email address from userdetails where emailaddress like '%$email%'"); 
while ($row = mysql_fetch_array($sql)){ 
echo '<br/> First Name: '.$row['forename']; 
echo '<br/> Last Name: '.$row['surname']; 
echo '<br/><br/>'; 
} 
?>

The search functionality works fine, but I can't work out how to populate the forename and surname fields on my form from the records retrieved from my database. I've been looking for, and found examples on how to do this, if I want to simply show the data as a table, but I can't find any that explain how to populate the fields in a form.

I just wondered whether it would be at all possible that someone could provide some guidance please on how I can do this.

Many thanks


The previous answer will work fine if short tags are enabled on the server. You should stick to the long syntax as below in case you change hosting providers at a later date.

<input name="fname" type="text" id="fname" size="30" value="<?php echo $row['surname']; ?>" />


just set the value of your input element

        <tr>
            <td height="25"><strong>First Name </strong></td>
            <td>&nbsp;</td>
            <td><input name="fname" type="text" id="fname" size="30" value="<?= $row['surname'] ?>" /></td>
        </tr>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜