View Full Version : PHP redirection

10-27-2009, 05:45 AM
Need help urgently on PHP project that Im working on. This is for my work and I've been instructed to develop a website/blog. I've got the website up and running and everything however I would like it to redirect to the messageboard after a message has been posted from a form. Sort of like what codingforums has after logging in, it will redirect to the page where messages can be posted. How can this be accomplished using php or is JavaScripted needed for this. Any help appreciated.

10-27-2009, 05:52 AM
header("refresh: 3; url=wheretoredirect");

That will redirect you after 3 seconds, to wheretoredirect (change this to your page).

10-27-2009, 06:02 AM
ok will give it a shot and let you know if it works,thx

10-27-2009, 06:07 AM
Hey bud is this right way?

header("refresh: 3; url=message_board.php");
<?php // Script 12.5 - add_entry.php
// This script adds an entry to the database.

// Address error handing.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

if (isset ($_POST['submit'])) { // Handle the form.

// Connect and select.
if ($dbc = @mysql_connect ('localhost', 'postc3', 'jesy+qrp')) {

if (!@mysql_select_db ('msgboard')) {
die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>');

} else {
die ('<p>Could not connect to MySQL because: <b>' . mysql_error() . '</b></p>');

// Define the query.
$query = "INSERT INTO entry (name, message, date) VALUES ('{$_POST['from']}', '{$_POST['message']}', NOW())";

// Execute the query.

if (@mysql_query ($query)) {
print '<p>The message has been added.</p>';

} else {
print "<p>Could not add the message because: <b>" . mysql_error() . "</b>. The query was $query.</p>";



// Display the form.
<form action="form.php" method="post">
<p>From: <input type="text" name="from" size="40" maxsize="100" /></p>
<p>Message: <textarea name="message" cols="40" rows="5"><?php
$message = $_GET['msg'];
print "Enter your message here:&nbsp;";
<input type="submit" name="submit" value="Submit" /></form>

10-27-2009, 06:11 AM
It didn't work corrected the code by placeing php tags around the code u supplied but it hust stays on the same form still

the website can be viewed at www.postcardsfromheaven.co.nz

10-27-2009, 07:56 AM
Thanks got it going