Jump to content

[SOLVED] Redirect On Submit With Form Using $_SERVER['PHP_SELF'];


jadedknight

Recommended Posts

Soo 10 min later Im back at it again :P I would like my script to redirect after I submit and process the form.

 

Form Code.

require('db-connect.php');

 

$title = $_POST['title'];

$author = $_POST['author'];

$date = $_POST['date'];

$content = $_POST['content'];

 

$query = "INSERT INTO posts (title, author, date, content) VALUES ('$title', '$author', '$date', '$content')";

if (mysql_query($query)) {

print "<script language=\"Javascript\">document.location.replace('index.php')</script >";

} else {

die(mysql_error());

}

mysql_close();

 

?>

 

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

 

<p>Title:</p>

<p><input class="required" id="field-title" type="text" name="title" /></p>

<p>Author:</p>

<p><input class="required" id="field-author" type="text" name="author" /></p>

<p>Date:</p>

<p><input class="required" id="field-date" type="text" name="date" /></p>

<p>Content: </p>

<p><textarea class="required" id="field-content" name="content" rows="5" cols="50"></textarea></p>

<p><input type="submit" value="Submit Post" /></p>

<p><input type="reset" value="Reset Fields" onclick="valid.reset(); return false" /></p>

 

</form>

 

As you can see I am trying to redirect within an IF statement, however in its current state the $query check is always true, so I cant even access the page. How do I go about redirecting? Thank you ^^

Hello again xP

 

   if (mysql_query($query)) {
     
        header("Location: index.php");

   } else {
      die(mysql_error());
   }

 

That just may work...don't hold me to it though =)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.