I am trying to pass a variable in a URL within a header function. I know I can do it like this
index2.php?ID=<?=$objResult["ID"];?>
if its not in a header function. However if I try to do this in the header function my whole script crashes. I have also tried this:
header("Refresh: 5;url=index2.php?ID=".$objResult["ID"]."");
but that gives the following error:
Warning: Cannot modify header information - headers already sent by (output started at /var/www/Mail/index.php:25) in /var/www/Mail/index.php on line 33
(Line 33 is the header line)
My whole code is this:
<?php
if($_POST)
{
mysql_connect('localhost','root','root');
mysql_select_db('NAW') or die (mysql_error());
$Naam = $_POST['naam'];
$Email = $_POST['email'];
$Soort = $_POST['soort'];
$sql = mysql_query("INSERT INTO Klant (Naam, Email, Soort) VALUES ('".$Naam."', '".$Email."', '".$Soort."')") or die (mysql_error());
if ($sql === false) {
die (mysql_error());
}
else {
echo ''.$Naam.' is in de database toegevoegd.<br><br>';
}
$strSQL = ("SELECT * FROM Klant WHERE Naam='".$Naam."'");
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
header("Refresh: 5;url=index2.php?ID=".$objResult["ID"]."");
if($sql){ return 1; } else { return 0; }
}
?>
If anyone can tell me what I am doing wrong on push me in the right direction it would be great!
NOTE:
I know I shouldn't be using mysql_* because of sql injections but since this code will never be online and only used local this is not a problem