My php code has a html form nested between two blocks of php.
When I open this in browser the form does not appear.
I don't get any error messages.
I think my problem is that I do not know how to properly include this html within my if and else if statements.
When I view source on web page there is nothing there.
I can only assume that is because the form is between the php code blocks.
I thought escaping the php , marking-up the <form> , then reentering php would allow the form to be rendered by the browser.
I have tried to use <html><body><form> my form </form></body></html> but that hasn't helped.
I have tried relocating the code block for the form. When I put it right after the reqiure statement the form was rendered and inputs created expected results.
However, I believe I will need this form to be within between the php code blocks so that I can store user input in variables and display in the form.
core.inc.php
<?php
ob_start();
session_start();
$current_file = $_SERVER ['SCRIPT_NAME'];
//$http_referer = $_SERVER ['HTTP_REFERER'];
function loggedin () {
if (isset ($_SESSION ['user_id']) && !empty ($_SESSION ['user_id'])) {
return true;
} else {
return false;
}
}
function getuserfield ($field) {
$query = "SELECT `$field` FROM `users` WHERE `id` = '".$_SESSION ['user_id']."'";
if ($query_run = mysql_query ($query)) {
if ($query_result = mysql_result ($query_run, 0, $field)){
return $query_result;
}
}
}
?>
register.php
<?php
require 'core.inc.php';
if (!loggedin()){
if (isset ($_POST ['username'])&& isset ($_POST ['password'])&& isset ($_POST ['password_again'])&& isset ($_POST ['firstname'])&& isset ($_POST ['lastname']))
{
$username = $_POST ['username'];
$password = $_POST ['password'];
$password_again = $_POST ['password_again'];
$firstname = $_POST ['firstname'];
$lastname = $_POST ['lastname'];
if (!empty ($username)&& !empty ($password)&& !empty ($password_again)&& !empty ($firstname)&& !empty ($lastname))
{
echo 'OK';
} else {
echo '<strong><font color= "red">All fields are required!</font> </strong>';
}
?>
<form action = "register.php" method = "POST" >
Username:<br> <input type = "text" name = "username" value = "<?php echo $username; ?>"><br><br>
Password:<br> <input type = "password" name = "password"><br><br>
Password again:<br><input type = "password" name = "password_again"><br><br>
Firstname: <br><input type = "text" name = "firstname" value = "<?php echo $firstname; ?>"><br><br>
Lastname: <br><input type = "text" name = "lastname" value = "<?php echo $lastname; ?>"><br><br>
<input type = "submit" value = "Register">
</form>
<?php
} else if (loggedin()) {
echo 'You\'re already registered and logged in.';
}
}
?>