Been adding some code to a site. Have run into a problem, though similar code works in alternate pages, it will not work here. The problem revolves around redirecting through the header command.
Any thoughts or ideas?
I have been going back and examining my coding that has been working 100% and tweaking this code. I am going to give you an example of the one that is working and then my revised code.
Working:
<?php //DELETE the information script
if (isset ($_POST['submit'])) { // Handle the form.
$editUserType = $_SERVER['PHP_SELF'];
include ('../../connections/connMI.php'); //establish connections to database
//select the database
mysql_select_db ($database_connMI) or die ('<p>Could not select the database because <b>' .mysql_error().'</b></p>');
//define the query
$query = "DELETE FROM usertype
WHERE TypeID={$_GET['TypeID']} LIMIT 1";
//execute the query
if (@mysql_query ($query)) {
header ("Location: ./index.php"); //redirect to UserType index page
mysql_close(); //close the database
exit(); //exit the script
} else {
echo "<p>Could not delete the entry because: <b>" .mysql_error(). "</b>.<br /> The query was $query.</p>";
}
}
?>
Not working:
<?php
//get the information from the form
$addUser = $_SERVER['PHP_SELF']; //trigger
if (isset($_POST['Submit'])) { //handle the form
//define the variables
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$Email = $_POST['Email'];
$AccessLevel = $_POST['AccessLevel'];
//connect to the database
mysql_select_db($database_connMI, $connMI) or die ('<p>Could not select the database because <b>' .mysql_error().'</b></p>');
//define the string and the query
$query = "INSERT INTO `user` (Username, Password, FirstName, LastName, Email, AccessLevel) VALUES ('$Username', '$Password', '$FirstName', '$LastName', '$Email', '$AccessLevel')";
//execute the query
if (@mysql_query ($query)) {
header ("Location: ./index.php"); //redirect to UserType index page
mysql_close(); //close the database
exit(); //exit the script //exit the script
} else {
echo "<p>Could not add the entry because: <b>" .mysql_error(). "</b>.</p>";
}
}
?>
In this second example, note that I have already established the connection to the server and have selected the database. Between these two is some code that allows for a dynamic drop down box to select my UserType (a couple of record sets, no html, print or echo).