Reputation: 47
I need to build HTML page to show and organize my results. Where do I place the HTML? I tried it and I get errors. Does it go inside the php script? after the php script? before? Confused.
<?php
if (isset($_POST['Submit'])) {
if (!empty($_POST['reg'])) {
$record = $_POST['reg'];
$query = mysql_query("SELECT * FROM reg_add WHERE reg='" . mysql_real_escape_string($record) . "'");
$result = mysql_num_rows($query);
if ($result != 0) {
$row = mysql_fetch_array($query);
$connect_date = $row['connect_date'];
$reg = $row['reg'];
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$nickname = $row['nickname'];
$gender = $row['gender'];
$birthday = $row['birthday'];
$home_state = $row['home_state'];
$national = $row['national'];
$location = $row['location'];
} else {
header("Location: search_error1.php");
exit;
}
} else {
header("Location: search_error2.php");
exit;
}
}
?>
Upvotes: 0
Views: 2649
Reputation: 1228
PHP is embeddable into HTML, so you can write your html markup right in php file. You just need to place all your php code inside <?php ?>
:
<?php
//php code
?>
<html>
<!-- ... -->
</html>
<?php /* php again */ ?>
PHP interpreter simply ignores all text written outside the php tag (<?php ?>
) and writes it directly to stdout.
So for you it will be something like this:
<?php
// ...
if ($result != 0) {
while($row = mysql_fetch_array($query)) {
$connect_date = $row['connect_date'];
$reg = $row['reg'];
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$nickname = $row['nickname'];
$gender = $row['gender'];
$birthday = $row['birthday'];
$home_state = $row['home_state'];
$national = $row['national'];
$location = $row['location'];
?>
First name: <?php echo $first_name ?><br/>
Last name: <?php echo $last_name ?><br/>
...
<?php
}
}
// ...
?>
Upvotes: 2