I have a webform with basic info (Fname, Lname, Uname, Email, Phumber, Age, Facebook, Major, Education, Music, Fav, message
)
After submitting the form, and inserting the data of those fields into a MySQL database, I want to be able to be redirected to a different URL.
I tried using the header function for PHP but for some reason it will not redirect me to the URL I specified.
<?php
ob_start();
require("config.php");
include 'config.php';
ini_set('display_errors', 0);
if($_GET['action'] == 'check')
{
if($_POST['Fname'] == '' || $_POST['Lname'] == '' || $_POST['Uname'] == '' || $_POST['Email'] == '' || $_POST['Phumber'] == '' || $_POST['Age'] == '' || $_POST['Facebook'] == '' || $_POST['Major'] == '' || $_POST['Education'] == '' || $_POST['Music'] == '' || $_POST['Fav'] == '' || $_POST['message'] == '')
{
exit;
}
else
{
if($_POST['Email'] !== $_POST['Email'])
{
exit;
}
else
{
$result = mysql_query("SELECT * FROM loginphp
WHERE Uname='{$_POST['Uname']}'") or die(mysql_error());
$row = mysql_fetch_array( $result );
if($row['Uname'] == '')
{
$_Fname = str_replace("<", "", $_POST['Fname']);
$_Lname = str_replace("<", "", $_POST['Lname']);
$_Uname = str_replace("<", "", $_POST['Uname']);
$_Email = str_replace("<", "", $_POST['Email']);
$_Phumber = str_replace("<", "", $_POST['Phumber']);
$_Age = str_replace("<", "", $_POST['Age']);
$_Facebook = str_replace("<", "", $_POST['Facebook']);
$_Major = str_replace("<", "", $_POST['Major']);
$_Education = str_replace("<", "", $_POST['Education']);
$_Music = str_replace("<", "", $_POST['Music']);
$_Fav = str_replace("<", "", $_POST['Fav']);
$_message = str_replace("<", "", $_POST['message']);
mysql_query("INSERT INTO loginphp
(Fname, Lname, Uname, Email, Phumber, Age, Facebook, Major, Education, Music, Fav, message) VALUES('$_Fname', '$_Lname', '$_Uname', '$_Email', '$_Phumber', '$_Age', '$_Facebook', '$_Major', '$_Education', '$_Music', '$_Fav', '$_message') ")
or die(mysql_error());
header("Location: main.php");
exit();
}
}
}
}
?>
Warning: Cannot modify header information - headers already sent by (output started at register.php:1) in register.php on line 47
-------------- The answer
This problem doesn't want to get solved so I add print with html code to redirect the page after insert the data to solve it
mysql_query("INSERT INTO loginphp
(Fname, Lname, Uname, Email, Phumber, Age, Facebook, Major, Education, Music, Fav, message) VALUES('$_Fname', '$_Lname', '$_Uname', '$_Email', '$_Phumber', '$_Age', '$_Facebook', '$_Major', '$_Education', '$_Music', '$_Fav', '$_message') ")
or die(mysql_error());
echo '<META HTTP-EQUIV="Refresh" CONTENT="0;URL=http://www.http://stackoverflow.com/">';
exit();
Thanks for everyone tried to help !