Disappearing Content with PHP execution.[Solved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Disappearing Content with PHP execution.[Solved]

Post 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");
}
}
?>
Last edited by scarface222 on Wed Apr 01, 2009 8:03 pm, edited 1 time in total.
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: Disappearing Content with PHP execution. Help appreciated.

Post by scarface222 »

Any ideas?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Disappearing Content with PHP execution. Help appreciated.

Post 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.
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: Disappearing Content with PHP execution. Help appreciated.

Post by scarface222 »

Sorry I was not aware. I am new to this forum.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: Disappearing Content with PHP execution. Help appreciated.

Post 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.
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: Disappearing Content with PHP execution. Help appreciated.

Post by scarface222 »

Thanks, appreciate it. I will see if I can find the error.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Disappearing Content with PHP execution. Help appreciated.

Post 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?
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: Disappearing Content with PHP execution. Help appreciated.

Post by scarface222 »

I did, no errors were reported when the content disappeared.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: Disappearing Content with PHP execution. Help appreciated.

Post 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.
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: Disappearing Content with PHP execution. Help appreciated.

Post by scarface222 »

Thank you very much. I used return and everything is working perfectly. Really appreciate the feedback.
Post Reply