PHP problem - Sorry cant really know what the problem is

+2 Jad Samadi · November 23, 2014
So hey there thanks for all your previous help . Now im stuck with a new problem :/ it may not be related to PHP but ill get to the point .
So after iv made a successful login/register system iv started to make a template to my website but iv been having this problem for some reason ...



When i try to include my register form and system it give me this :  

/images/forum/upload/2014-11-23/fe931fb55cda650548a4b968f9b6447f.png
This is how it look like when the code is : 

<?php include 'includes/header.php'; ?>

                  <div class="section">
                                                        <div>
<h3>Register</h3>
<div> 
<?php
require 'core.inc.php';
require 'connect.inc.php';

if (!loggedin()) {

  if (isset($_POST['username'])&& isset($_POST['password'])&&isset($_POST['password_again'])&&isset($_POST['firstname'])&&isset($_POST['surname']))
  $username = $_POST['username'];
  $password = $_POST['password'];
  $password_again = $_POST['password_again'];
  $firstname = $_POST['firstname'];
  $surname = $_POST['surname'];

  if (!empty($username)&&!empty($password)&&!empty($password_again)&&!empty($firstname)&&!empty($surname)){
 if ($password!=$password_again) {
      echo 'Passwords do not match<br><br>';
 } else {

      $query = "SELECT `username` FROM `users` WHERE `username`='$username'";
      $query_run = mysql_query($query);

      if (mysql_num_rows($query_run)==1) {
       echo 'The username '.$username.' already exists.<br><br> ';
      } else {
       $query = "INSERT INTO `users` VALUE ('','".mysql_real_escape_string($username)."','".mysql_real_escape_string($password)."','".mysql_real_escape_string($firstname)."','".mysql_real_escape_string($surname)."')";
       if ($query_run = mysql_query($query))  {
          header ('Location: register_success.php');
       } else {
          echo 'Sorry, we couldn\'t register you at this moment. Try again later.<br><br>';
       }
      }
 }

} else {
  echo 'All fields are required<br><br>';
}

} else if (loggedin()) {
  echo 'You\'r already registered and logged in.';
}

?>


<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>
Surname: <br> <input type="text" name="surname" value="<?php echo $surname?>"> <br><br>
<input type="submit" value="Register">
</form>

<?php include 'includes/footer.php'; ?>



And this is how it look : /images/forum/upload/2014-11-23/65643c9bfb0b94c54dbb7b70b4f52de5.png

When the code is like this :

<?php include 'includes/header.php'; ?>

                  <div class="section">
                                                        <div>
<h3>Register</h3>
<div>
<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>
Surname: <br> <input type="text" name="surname" value="<?php echo $surname?>"> <br><br>
<input type="submit" value="Register">
</form>




So if you can help me that would be great . Thanks and sorry for the long post :/.

Post a Reply

Replies

Oldest  Newest  Rating
0 Jad Samadi · November 23, 2014
Thanks for your help but apparently php was just trolling me... I removed than retyped <? Php tqg qnd it worked... 
0 Franz Schmidt · November 23, 2014
Sry but you need to post more code 
I need the header.php file and the file where you declaired the loggedin() function.

And just a little suggestion:
try to tipe
if(1)

instead of
if(!loggedin())

in your file
Just to see if this function isn't the failure.
0 Jad Samadi · November 23, 2014
the coming soon was from a previous code ... i changed it after :)  and  sure just a sec :) :

Register.php :

<?php include 'includes/header.php'; ?>

                  <div class="section">
                                                        <div>
<h3>Register</h3>
<?php
require 'core.inc.php';
require 'connect.inc.php';

if (!loggedin()) {

  if (isset($_POST['username'])&& isset($_POST['password'])&&isset($_POST['password_again'])&&isset($_POST['firstname'])&&isset($_POST['surname']))
  $username = $_POST['username'];
  $password = $_POST['password'];
  $password_again = $_POST['password_again'];
  $firstname = $_POST['firstname'];
  $surname = $_POST['surname'];

  if (!empty($username)&&!empty($password)&&!empty($password_again)&&!empty($firstname)&&!empty($surname)){
 if ($password!=$password_again) {
      echo 'Passwords do not match<br><br>';
 } else {

      $query = "SELECT `username` FROM `users` WHERE `username`='$username'";
      $query_run = mysql_query($query);

      if (mysql_num_rows($query_run)==1) {
       echo 'The username '.$username.' already exists.<br><br> ';
      } else {
       $query = "INSERT INTO `users` VALUE ('','".mysql_real_escape_string($username)."','".mysql_real_escape_string($password)."','".mysql_real_escape_string($firstname)."','".mysql_real_escape_string($surname)."')";
       if ($query_run = mysql_query($query))  {
          header ('Location: register_success.php');
       } else {
          echo 'Sorry, we couldn\'t register you at this moment. Try again later.<br><br>';
       }
      }
 }

} else {
  echo 'All fields are required<br><br>';
}


} else if (loggedin()) {
  echo 'You\'r already registered and logged in.';
}

?>
<div>
<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>
Surname: <br> <input type="text" name="surname" value="<?php echo $surname?>"> <br><br>
<input type="submit" value="Register">
</form>




Loginform.inc.php: (login file):


<?php include 'includes/header.php'; ?>

                  <div class="section">
                                                        <div>
<h3>Log in</h3>
<div>
                                                        <?php

if (isset($_POST['username'])&&isset($_POST['password'])) {
  $username = $_POST['username'];
  $password = $_POST['password'];

  if (!empty($username)&&!empty($password)) {

    $query = "SELECT `id` FROM `users` WHERE `username`='".mysql_real_escape_string($username)."' AND `password`='".mysql_real_escape_string($password)."'";
    if ($query_run = mysql_query ($query)) {
     $query_num_rows = mysql_num_rows($query_run);

     if ($query_num_rows==0) {
        echo 'Invalid username and password combination<br><br>';
     } else if($query_num_rows==1){
       $user_id = mysql_result($query_run, 0, 'id');
       $_SESSION['user_id'] =$user_id;
       header('Location: home.php');

     }
    }

  } else {
    echo 'You must supply a username and a password<br><br>';
  }
}

?>

<form action="<?php echo $current_file; ?>" method="POST">
Username: <input type="text" name="username"> <br><br>Password :  <input type="password" name="password"><br><br>
 <input type="submit" value="Log in"> 
</form>
<?php include 'includes/footer.php'; ?>

includes/menu.php :

<?php

require 'core.inc.php';
require 'connect.inc.php';

if (loggedin()) {

$username = getuserfield('username');

 echo '<li class="selected">
<a href="home.php" id="menu1">home</a>
</li>
<li>
<a href="Features.php" id="menu2">Features</a>
</li>
<li>
<a href="Contact.php" id="menu3">Contact</a>
</li>
<li>
<a href="logout.php" id="menu4">Logout</a>
</li>' ;

} else {
echo '<li class="selected">
<a href="home.php" id="menu1">home</a>
</li>
<li>
<a href="Features.php" id="menu2">Features</a>
</li>
<li>
<a href="Contact.php" id="menu3">Contact</a>
</li>
<li>
<a href="loginform.inc.php" id="menu4">Login</a>
</li>
<li>
<a href="register.php" id="menu5">Register</a>
</li>';
}

?>



So in the login page it work and i can login and all work just in register :/ 
0 Franz Schmidt · November 23, 2014
I don't know how this "COMING SOON" text appears there...
And if I try your code without the headers you included it works fine :/

Could you please post all of your code as well (also the php files you include on several points).
0 Jad Samadi · November 23, 2014
its like when i remove all the php commands and functions it work but when i add them it become missed up :/
  • 1

PHP

107,272 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators