Given the following piece of code, I was looking for suggestions on how to beautify
the portion of the HTML where I jump out of php mode and back in again. The HTML does
not have any indenting in order to make the output more readable. However, by not
indenting the php code, the php code becomes slightly more difficult to read. Is there
a way to have both the php and HTML codes indent correctly?
Thanks.
<?php
} else {
// Connect to the database.
$dbConnection = dbConnect($dbHo st, $dbUser, $dbPassword, $db);
// Check required fields.
if ($_POST['newid'] == '' or $_POST['newname'] == '' or $_POST['newemail'] == '') {
errorMessage("O ne or more required fields were left blank. Please fill them in and try again.");
}
$query = "SELECT COUNT(*) FROM user WHERE userid = '$_POST[newid]'";
$result = mysql_query($qu ery);
if (!$result) {
errorMessage("A database error occurred.");
}
// Check to see if the userid already exists.
if (mysql_result($ result, 0, 0) > 0) {
errorMessage("A user with the user id you requested already exists.");
}
$newpassword = "test";
$query = "INSERT INTO user SET
userid = '$_POST[newid]',
password = PASSWORD('$newp assword'),
fullname = '$_POST[newname]',
email = '$_POST[newemail]',
notes = '$_POST[newnotes]'";
if (!mysql_query($ query)) {
errorMessage("$ query");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<TITLE>Registra tion SUCCESS!</TITLE>
</head>
<body>
Database insertion was successful. You are now registered.
</body>
</html>
<?php
}
?>
the portion of the HTML where I jump out of php mode and back in again. The HTML does
not have any indenting in order to make the output more readable. However, by not
indenting the php code, the php code becomes slightly more difficult to read. Is there
a way to have both the php and HTML codes indent correctly?
Thanks.
<?php
} else {
// Connect to the database.
$dbConnection = dbConnect($dbHo st, $dbUser, $dbPassword, $db);
// Check required fields.
if ($_POST['newid'] == '' or $_POST['newname'] == '' or $_POST['newemail'] == '') {
errorMessage("O ne or more required fields were left blank. Please fill them in and try again.");
}
$query = "SELECT COUNT(*) FROM user WHERE userid = '$_POST[newid]'";
$result = mysql_query($qu ery);
if (!$result) {
errorMessage("A database error occurred.");
}
// Check to see if the userid already exists.
if (mysql_result($ result, 0, 0) > 0) {
errorMessage("A user with the user id you requested already exists.");
}
$newpassword = "test";
$query = "INSERT INTO user SET
userid = '$_POST[newid]',
password = PASSWORD('$newp assword'),
fullname = '$_POST[newname]',
email = '$_POST[newemail]',
notes = '$_POST[newnotes]'";
if (!mysql_query($ query)) {
errorMessage("$ query");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<TITLE>Registra tion SUCCESS!</TITLE>
</head>
<body>
Database insertion was successful. You are now registered.
</body>
</html>
<?php
}
?>
Comment