Page 1 of 1

Disappearing Content with PHP execution.[Solved]

Posted: Mon Mar 30, 2009 7:34 pm
by scarface222
Hey guys, I am still in the learning stages of web development and I was wondering if there were any experts who had any idea of how to solve my problem. On the index page of my website, there is an include which validates the user with PHP when they create a profile. For example, if the username exists, PHP code is used to echo that and prevent the user from moving forward. However when there is a problem and the PHP code executes and echos the issue, certain content on the page disappears: the include footer, and the "createscription" writing just above it (highlighted in red). Any feedback is greatly valued and appreciated.

PS sorry for the mess, I am going to organize all the code later on and I thought maybe it would help if I include all of it.

Index Code

Code: Select all

<?php require_once("includes/connection.php"); ?>
<html>
<head>
<title></title>
    <link rel="shortcut icon" href="images/iconlogomini2.png" >
    
    <link href="stylesheets/main_pages.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
#border {
    border: 1px solid #999;
    padding: 10px;
    background-color: #EDE6D8;
}
#description1 {
    position: absolute;
    top: 50%;
    margin-top:-150px;
    text-align: center;
    width:435;
}
#divalignmain {
    height: 600px;
    width: 1024px;
    position: absolute;
    left: 50%;
    margin-left: -512px;
}
.paddingright {
    padding-right: 25px;
}
#footer {
    position: absolute;
    bottom: 0px;
    margin:auto;
}
#content1 {
    position: absolute;
    top: 50%;
    margin-top: -100px;
}
#content2 {
    position: absolute;
    right:0px;
    top: 50%;
    margin-top: -140px;
}
.redtext {
    color: #B21F29;
}
.redtexterror {
    color:#F00;
}
#createdescription {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: bold;
}
 
-->
</style>
 
<script language="javascript">
function changeBox() 
{
  document.getElementById('div1').style.display='none';
  document.getElementById('div2').style.display='';
  document.getElementById('password').focus();
}
function restoreBox() 
{
    if(document.getElementById('password').value=='')
    {
      document.getElementById('div1').style.display='';
      document.getElementById('div2').style.display='none';
    }
}
 
function changeBox2() 
{
  document.getElementById('div3').style.display='none';
  document.getElementById('div4').style.display='';
  document.getElementById('username').focus();
}
function restoreBox2() 
{
    if(document.getElementById('username').value=='')
    {
      document.getElementById('div3').style.display='';
      document.getElementById('div4').style.display='none';
    }
}
</script>
 
</head>
 
<body>
<div id="divalignmain">
<form action="" method="post">
<table width="1024" height="80" border="0" align="right" cellpadding="5" id="headerform" class="paddingright">
  <tr>
    <td align="right"><div id="div3"><input name="user_temp" type="text" value="Username" size="20" maxlength="20" style="border:#B21F29; color:#999" onFocus="changeBox2()" />
</div>
<div id="div4" style="display:none"><input name="username" id="username" type="text" value="" size="20" style="border:#B21F29;" maxlength="20" onBlur="restoreBox2()" />
</div></td>
  </tr>
  <tr>
    <td align="right"><div id="div1"><input name="pass_temp" type="text" value="Password" size="20" maxlength="20" style="border:#B21F29; color:#999" onFocus="changeBox()" />
</div>
<div id="div2" style="display:none"><input name="password" id="password" type="password" value="" size="20" style="border:#B21F29;" maxlength="20" onBlur="restoreBox()" />
</div></td>
    <td width="10px"><input type="image" name="login" src="images/loginbutton.gif" /></td>
  </tr>
</table>
</form>
 
<div id="description1">
<img src="images/description1.gif"></div>
 
 
<div id="content1"><img src="images/titleimage.gif" alt="home image"></div>
 
<div id="content2"><form action="index.php" method="post">
<table width="250" border="0" cellpadding="3" id="border">
  <tr>
  <td><img src="images/createwriting.gif"></td>
  </tr>
  <tr>
    <td class="redtext">Create Username: <input name="username" type="text" size="40" maxlength="50"/></td>
  </tr>
  <tr>
    <td class="redtext">Create Password: <input name="password" type="password" size="40" maxlength="50"/></td>
  </tr>
  <tr>
    <td class="redtext">Confirm Password: <input name="confirm_password" type="password" size="40" maxlength="50"/></td>
  </tr>
  <tr>
  <td align="right"><input name="submit" type="image" src="images/createbutton.gif" />
  </form>
  </td>
  </tr>
  <tr>
  <td class="redtexterror">
<?php require ("includes/create_authentication.php"); ?>
</td>
</tr>
   <tr>
  [color=#BF0000]<td id="createdescription">******************************</td>[/color]
</tr>
</table>
</div>
[color=#BF0000]<div id="footer"> <?php require ("includes/footer_close_connection.php"); ?> </div>[/color]
</div>
</body>
</html>
PHP create_authentication

Code: Select all

<?php 
if (isset($_POST['username'])){
$username=mysql_real_escape_string($_POST["username"]);
$password=$_POST["password"];
$confirm_password=$_POST["confirm_password"];
$first_query="SELECT * FROM users WHERE username ='$username'";
$result=mysql_query($first_query);
$count=mysql_num_rows($result);
 
if ($password==""){
echo 'please fill in all fields';
    die();
}
if ($username==""){
echo 'please fill in all fields';
    die();
}
if ($confirm_password==""){
echo 'please fill in all fields';
    die();
}
else if ($count>0){
    echo 'user exists';
    die();
}
else if ($password!=$confirm_password){
echo 'passwords do not match';
    die();
}
 
else{
    $second_query = "INSERT INTO users (username,password) VALUES ('$username', '$password')";
mysql_query($second_query) or die('Error, insert query failed');
 
mkdir("../usercontent/$username",0777);
 
session_register();
    session_start();                      
    $_SESSION['username'] = $username;
    $_SESSION['password'] = $password;
    
header("location:preferences.php");
}
}
?>

Re: Disappearing Content with PHP execution. Help appreciated.

Posted: Tue Mar 31, 2009 3:00 pm
by scarface222
Any ideas?

Re: Disappearing Content with PHP execution. Help appreciated.

Posted: Tue Mar 31, 2009 3:18 pm
by Benjamin
There are rules against bumping posts within 24 hours just to let you know. This is the second time you have bumped one of your posts.

Re: Disappearing Content with PHP execution. Help appreciated.

Posted: Tue Mar 31, 2009 7:47 pm
by scarface222
Sorry I was not aware. I am new to this forum.

Re: Disappearing Content with PHP execution. Help appreciated.

Posted: Tue Mar 31, 2009 10:17 pm
by php_east
when php encounters a fatal error it exits immediately. your remaining codes after

Code: Select all

<?php require ("includes/create_authentication.php"); ?>
nail down that bug/code in create_authentication.php and ensure create_authentication.php recovers gracefully from any major fault.

Re: Disappearing Content with PHP execution. Help appreciated.

Posted: Wed Apr 01, 2009 1:46 am
by scarface222
Thanks, appreciate it. I will see if I can find the error.

Re: Disappearing Content with PHP execution. Help appreciated.

Posted: Wed Apr 01, 2009 1:46 am
by Benjamin
scarface222 wrote:Thanks, appreciate it. I will see if I can find the error.
Have you thought about turning on error reporting and display errors?

Re: Disappearing Content with PHP execution. Help appreciated.

Posted: Wed Apr 01, 2009 3:11 pm
by scarface222
I did, no errors were reported when the content disappeared.

Re: Disappearing Content with PHP execution. Help appreciated.

Posted: Wed Apr 01, 2009 5:45 pm
by php_east
i should have said "when php encounters a fatal error OR a die() command or an exit() command it exits immediately." try and use return instead of die. if php is dead it will not see the rest of your code.

Re: Disappearing Content with PHP execution. Help appreciated.

Posted: Wed Apr 01, 2009 8:03 pm
by scarface222
Thank you very much. I used return and everything is working perfectly. Really appreciate the feedback.