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.';
}
}
?>

    Why are you calling ob_start(), and where then is ob_flush?

    If you never flush the output buffer I wouldn't expect to see anything at all. If your session_start() is at the top of the script you probably don't need ob_start() anyway.

      To be honest with you I didn't even know what ob_start was and that at some point it should be followed by ob_flush,untill I read your post and googled it. As i now understand it it has something to do with reserving physical memory for processing. So I don't know why it is being called.
      I am just following a tutorial which interconnects several php files:
      log_in.php
      core.inc.php
      loginform.inc.php
      register.php
      logout.php
      In the tutorial the first bit of code is to require core.inc.php in the register.php file.

      I commented out //ob_start()
      in the core.inc.php
      This does not resolve the issue of the form not being displayed.

      Perhaps I should try annother tutorial source.
      Preferably video type.
      Any suggestions?

      P.S.
      I almost feel that I am being chastised here.
      There is a reason that my user name is New_PHP_Guy and I am posting in the newbies forum.

        New_PHP_Guy;11060535 wrote:

        P.S.
        I almost feel that I am being chastised here.
        There is a reason that my user name is New_PHP_Guy and I am posting in the newbies forum.

        Well, it's just a matter of being responsible for your own code (if you don't know what you wrote and why you can't expect anyone else to). I don't know what tutorials you were following (maybe output buffering was handled in an earlier episode), but if you're just copying stuff without understanding then you're not learning and the tutorial is failing you.

          New_PHP_Guy;11060535 wrote:

          I almost feel that I am being chastised here.
          There is a reason that my user name is New_PHP_Guy and I am posting in the newbies forum.

          I assure you I have no such intent. Welcome to the internet, where feelings cannot be conveyed through text alone. 🙂

            Thanks to all for the replies.
            After going through the tutorial again, the stated purpose of the ob_start()is as follows: This is required because we are using header function in the log out page to redirect user back to log_in.php and because we are giving out-put before we start here on the registration page. Since my last post I have resolved the issue of the non appearance of the form, but now have some other issues to contend with.

            I will try to take greater responsibility and care with my code. I will also seek other learning resources.
            Thank you all again.
            I will mark as resolved.

              New_PHP_Guy;11060601 wrote:

              ...I will also seek other learning resources....

              It's an ongoing process, and the learning never ends. 🙂 It's good to try different sources, and different types of sources, too. One drawback of PHP's long-time popularity and relative ease to start using, is that there is a lot of outdated stuff out there about it now, and some just plain bad stuff. I'm not saying that tutorial is necessarily either, as I've not looked at; just that you should be aware that anything you read on the web about it is not guaranteed to represent current best practices. 🙁 And, of course, "current best practices" is subject to arguments, anyway. 😉

                Write a Reply...