alby1481
alby1481

Reputation: 39

Define a SQL query to call on

Say I have the following php code:

$sql = "SELECT firstname FROM contact WHERE '{$_REQUEST['userid']}' = contactid";
$rs = $conn->Execute($sql);
if (!$rs) {
print $conn->ErrorMsg();
}
else {
while (!$rs->EOF) {
print $rs->fields[0].'<br>';
$rs->MoveNext();  //  Moves to the next row
}}

Which works well, however, how can I define that scrip/code to have the following in my form:

<p>First Name: <?php $whatever_it_can_be ?></p>

Upvotes: 0

Views: 355

Answers (1)

mellamokb
mellamokb

Reputation: 56779

else {
    if (!$rs->EOF) {
        $firstname = $rs->fields[0];
    } else {
        // user id is invalid
    }
}

Then in the page:

<p>First Name: <?php echo $firstname; ?></p>

Upvotes: 1

Related Questions