I've modified your code to hopefully guide you in the right direction. This code is untested. Hopefully if someone sees something wrong with it, they will point it out.
PHP Code:
<?php
// enable output buffering so headers will be sent first
ob_start();
$db_server="localhost";
$db_username="forrestj_admin";
$db_password="";
$db_name="forrestj_bxgmembers";
if ($_POST['btnSubmit'] )
{
$escpFirstname = mysql_escape_string(trim($_POST['firstname']) );
$escpLastname = mysql_escape_string(trim($_POST['lastname']) );
$escpUsername = mysql_escape_string(trim($_POST['username']) );
$escpPassword = mysql_escape_string(trim($_POST['password']) );
// This is where it processes the register.php form and adds the user
if ($id=="register")
{
$db = mysql_connect($db_server, $db_username, $db_password);
mysql_select_db($db_name, $db);
$result = mysql_query("SELECT * FROM attendies WHERE username='$escpUusername'", $db);
if (mysql_num_rows($result) > 0 )
{
echo 'That alias already exists in our database.';
header("Location: http://www.yoursite.com/register.php");
// should always "exit;" after sending a header.
exit;
}
else
{
$md5password = md5($escpPassword);
$sql = "INSERT INTO attendies (firstname,lastname,alias,password) VALUES ('$escpFirstname','$escpLastname','$escpUusername','$md5password')";
mysql_query($sql) or die(mysql_error());
echo 'You have been added to our database. Thanks for your interest.';
header("Location: http://www.yoursite.com/attendies.php");
exit;
}
}
// This is where it processes the deregister.php form and deletes the user
if ($id=="deregister")
{
$md5password = md5($escpPassword);
$db = mysql_connect($db_server, $db_username, $db_password);
mysql_select_db($db_name, $db);
$result = mysql_query("SELECT * FROM attendies WHERE username='$escpUusername' AND password='$md5password'", $db);
if (mysql_num_rows($result) > 0 )
{
$sql = "DELETE FROM attendies WHERE username='$escpUsername'";
if ($result = mysql_query($sql) )
{
echo 'You were removed successfully.';
header("Location: http://www.yoursite.com/deregister.php");
exit;
}
else
{ echo 'Error removing user';
// may want to log your error to file and maybe do some other stuff
// to help you figure out why this failed. This could be a bug that
// happens often.
header("Location: http://www.yoursite.com/wherever.php");
exit;
}
}
else
{
echo 'That username/password combination doesnt exist in our database.';
header("Location: http://www.yoursite.com/deregister.php");
exit;
}
}
}
// flush buffered output
ob_end_flush();
?>
Edit:
I've just sort of pretended that the values being sent through the form are firstname, lastname, username, and password. You can change these to match the names you are really using. It also looks like you are using 'alias' in the database as your username, you can change it accordingly. I just used the names I felt most comfortable with(the ones I'm used to using).
--ed
Bookmarks