Header already sent
Hello,
Please excuse me. I know this has been discussed before. I am trying to make a simple user registration form. When the submit botton is pressed I always seem to get
"Warning: Cannot modify header information - headers already sent in C:\xampp\htdocs\cdlist\Untitled-1.php on line 45"
The main code is:
<?php virtual('/cdlist/Connections/cdlist.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO users (username) VALUES (%s)",
GetSQLValueString($_POST['name'], "text"));
mysql_select_db($database_cdlist, $cdlist);
$Result1 = mysql_query($insertSQL, $cdlist) or die(mysql_error());
$insertGoTo = "yes.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s",$insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table width="500" border="1">
<tr>
<td>cd name
<label>
<input type="text" name="name" id="name" />
<input type="submit" name="button" id="button" value="Submit" />
</label></td>
</tr>
<tr>
<td>cd type
<label>
<input type="text" name="type" id="type" />
<input type="reset" name="button2" id="button2" value="Reset" />
</label></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>
The associated file for the main page cdlist.php is :
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_cdlist = "localhost";
$database_cdlist = "one_stop";
$username_cdlist = "root";
$password_cdlist = "enterprise";
$cdlist = mysql_pconnect($hostname_cdlist, $username_cdlist, $password_cdlist) or trigger_error(mysql_error(),E_USER_ERROR);
?>
The page that should come up is given by
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head><body>
yes it was inserted
</body>
</html>
I really have tried to find the solution and I really don't understand why this doesn't work. Please, any help would be really appreciated.
Thanks