Jump to content

Recommended Posts

HI,
i have this code:


PHP Code:
<?php include ('header.inc'); ?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">


<p><b>title</b> <input type="text" name="title" size="10" maxlength="20" value="" /></p>

<p><b>body</b><textarea name="body" rows="10" columns="50"></textarea></p>

<p>category</p><select name="category">
    <option value="fish">fiah</option>
    <option value="fish"></option>
   
</select>
<div align="center"><input type="submit" name="submit" value="submit" /></div>

<?php
if(isset($_POST['submit'])) {
   

    if(isset($_POST['title'])) {
    $title = ($_POST['title']);
    }
    else {
    $title = NULL;
    }

    if(isset($_POST['body'])) {
    $body = ($_POST['body']);
    }
    else {
    $body = NULL;
    }

    if(isset($_POST['category'])) {
    $category = ($_POST['category']);
    }
    else {
    $category = NULL;
    }

if ($title && $body && $category) {

        require_once ('mysql_connect.php');
       
        $query = "INSERT INTO entries (blog_id, title, date_submitted, category, body) VALUES (NULL, '$title', NOW(), '$category', '$body')";
        $result = mysql_query ($query);

        if($result) {
      echo '<p>entered please check the following</p>';
      echo "$title', '$body', '$category";
      exit();
        }

        else {
            echo '<p>there was an error</p>';
        }
       
}



else {
            echo '<p>there was an error</p>';
        }
}
echo '</form>';




 


?>

<?php include ('footer.inc'); ?>
I realise the code is probably a little antiquated ( im open to suggestions on how to improve it!) but it does do the job of validating my form and then inputting the data in to a database. Its my first script!

Anyways the problem im having is that if you are successful the browser re-loads the page with the correct things echoed back but the footer include is missing, it doesnt display.

could anyone tell me why?
Link to comment
https://forums.phpfreaks.com/topic/30879-why-does-this-page-redirect/
Share on other sites

HI,

Yeah sure. heres the header code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title><?php echo $page_title; ?></title>
</head>
<body bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="4">
  <tr>
    <td width="100%" bgcolor="#666666"><font color="#CCCCCC"><big><b>Welcome to my site!</b></big></font></td>
  </tr>
  <tr>
    <td bgcolor="#CCCCCC"> <table width="100%" border="0" cellspacing="1" cellpadding="2">
        <tr>
          <td align="center"><a href="index.php">Home</a></td>
          <td align="center"><a href="dateform.php">Date Form</a></td>
          <td align="center"><a href="calculator.php">Calculator</a></td>
          <td align="center"><a href="register.php">Register</a></td>
        </tr>
      </table></td>
  </tr>
</table>
<br />
<!-- Script 3.2  header.inc ends here -->
<!-- PAGE SPECIFIC CONTENT STARTS HERE. -->


and heres the footer:
<!-- Script 3.3 footer.inc -->
<br />
<table width="100%" border="0" cellspacing="0" cellpadding="2" bgcolor="#CCCCCC">
  <tr>
    <td> <div align="center">&copy; 2003 Larry E. Ullman and DMC Insights, Inc.</div></td>
  </tr>
</table>
</body>
</html>

Please excuse the needless use of tables! I was following a tut that used this header and footer and just re-used them here!
It is because you have exited the script, which is basically saying "stop here please!":
[code]<?php
if($result) {
        echo '<p>entered please check the following</p>';
        echo "$title', '$body', '$category";
        exit();
      }
?>[/code]

So:
[code]  <?php include ('header.inc'); ?>

  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">


  <p>title <input type="text" name="title" size="10" maxlength="20" value="" /></p>

  <p>body<textarea name="body" rows="10" columns="50"></textarea></p>

  <p>category</p><select name="category">
  <option value="fish">fiah</option>
  <option value="fish"></option>

  </select>
  <div align="center"><input type="submit" name="submit" value="submit" /></div>

  <?php
  if(isset($_POST['submit'])) {
    if(isset($_POST['title'])) {
      $title = ($_POST['title']);
    } else {
      $title = NULL;
    }
    if(isset($_POST['body'])) {
      $body = ($_POST['body']);
    } else {
      $body = NULL;
    }
    if(isset($_POST['category'])) {
      $category = ($_POST['category']);
    } else {
      $category = NULL;
    }
    if ($title && $body && $category) {
      require_once ('mysql_connect.php');
      $query = "INSERT INTO entries (blog_id, title, date_submitted, category, body) VALUES (NULL, '$title', NOW(), '$category', '$body')";
      $result = mysql_query ($query);
      if($result) {
        echo '<p>entered please check the following</p>';
        echo "$title', '$body', '$category";
      } else {
        echo '<p>there was an error</p>';
      }
    } else {
      echo '<p>there was an error</p>';
    }
  }
  echo '</form>';

  include ('footer.inc');
?>[/code]


AHHH The code tags are all messing up!

[i]EDIT2: I would suggest renaming your title (has nothing to do with redirecting ;))[/i]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.