Jump to content

Guest list website problem


foges

Recommended Posts

Hey, Im making a website with a guestlist and the login and register are working (at least in IE), but when i go to add people i get an error and the guests are not added. I am using mysql for my database and i know that it works because new users can register.

 

Here is what the "add_guest" page looks like:

 

NOTE: Please have a look for the

[b] and [/b] 

 

<?
$save = $_REQUEST["save"];

$guest = $_REQUEST["guest"];

if ($save == TRUE) {

//Print ("<pre>");
//Print_r ($_REQUEST);
//Print ("</pre>");

$res_userid = mysql_query ("SELECT user_id FROM grad_users WHERE user_name = '$grad_username'");

if ($U = mysql_fetch_array ($res_userid)) {

	$g = 5;

	foreach ($guest as $num => $names) {

		//Select the guests with the same name from the database
		$res_guests = mysql_query ("SELECT guest_id FROM grad_guests WHERE guest_name = '$names[name]' AND guest_surname = '$names[surname]'");

		if (mysql_num_rows ($res_guests) == 0) {

			if ($names["name"] != "" && $names["surname"] != "") {

				$query = "INSERT into grad_guests VALUES ('0','$names[name]','$names[surname]','$U[user_id]')";

				if (mysql_query($query) == TRUE) {
					$g++;
				}
			}

		} else {
			$errors[] = "The guest $names[name] $names[surname] is already invited.";
			$content .= errors_print ($errors);
		}
	}//End foreach

	$content .= "$g guests were successfully added.";

} else {

	[b]$errors[] = "The guests could not be added. Please try again.";[/b]
	$content .= errors_print ($errors);
}

} else {
$content .= "

<br>
<b><u>Add guests</u></b> | (You can add more than 5...just click add guests again when done.)<br>
<li><b>When adding guests make sure you use their <u>FULL name</u> and <u>Capital letters for first letters of names</u></b></li><br>
<li><b>Guests added <u>must</u> be over the age of <u>16</u> AND in or above <u>10th Grade</u>. We know who added who so no fucking around.</b></li><br>
<li><b>ONLY add guests you know are going to <u>most likely</u> show up.</b></li><br>
<br>

<form action=\"$_SERVER[php_SELF]\" method=\"post\">
<table width=\"75%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
";

for ($n = 1; $n <= 5; $n++) {
	$content .= "
	<tr>
		<td width=\"100%\" class=\"normal\" align=\"left\" colspan=\"4\"><strong>Guest #$n:</strong></td>
	</tr>
	<tr>
		<td width=\"20%\" class=\"normal\" align=\"left\">First name:</td>
		<td width=\"30%\" class=\"normal\" align=\"left\"><input type=\"text\" name=\"guest[$n][name]\"></td>
		<td width=\"20%\" class=\"normal\" align=\"left\">Last name:</td>
		<td width=\"30%\" class=\"normal\" align=\"left\"><input type=\"text\" name=\"guest[$n][surname]\"></td>
	</tr>
	";
}//End for

$content .= "
<tr>
	<td width=\"100%\" class=\"normal\" align=\"center\" colspan=\"4\">
	<input type=\"submit\" value=\"Add guests\">
	</td>
</tr>
</table>

<input type=\"hidden\" name=\"incpage\" value=\"addguest\">
<input type=\"hidden\" name=\"save\" value=\"TRUE\">
</form>
";
}//End if save
?>

 

It is linked to from this page:

 

<?
//Print ("<pre>");
//Print_r ($_REQUEST);
//Print_r ($_COOKIE);
//Print ("</pre>\n");

//Get login variables
$user_name = $_COOKIE["grad_username"];
$user_password = $_COOKIE["grad_password"];
if (!($user_login = $_COOKIE["grad_login"])) {
$user_login = FALSE;
}

$msg = $_REQUEST["msg"];
if (!($incpage = $_REQUEST["incpage"])) {
[b]$incpage = "addguest";[/b]
}

//Require the header page
require_once ("inc/header.php");

//Set check variables to FALSE in case login doesn't work
$user_logged_in = FALSE;
$user_level_logged = 1;

//Login check
if ($user_login == TRUE && $user_name != "" && $user_password != "") {
	$q_login = "SELECT user_name, user_password, user_level FROM grad_users WHERE user_name = '$user_name' LIMIT 1";
	$res_login = mysql_query ($q_login);

	if (mysql_num_rows ($res_login) == 1) {

		while($log = mysql_fetch_array($res_login)) {

			//DEBUG: Print structure of $log
			//Print ("<pre>");
			//Print_r ($log);
			//Print ("</pre>\n");

			if (($log["user_name"] === $user_name) && ($log["user_password"] === $user_password)) {//If username, password are correct
					$user_logged_in = TRUE;
					if ($log["user_level"] >= 2) {
						$user_level_logged = 2;
					}

			} else {
				$user_login = FALSE;
				$msg = "login_error";
			}
		}//End while

	} else {//If no data is set
		$user_login = FALSE;
		$msg = "login_error_nouser";
	}//End if database data found

}//End if user_login

if (!($user_login == TRUE && $user_name != "" && $user_password != "" && $user_level_logged >= 1)) {
//Create a new page for the HTML template class
$login = new htmltemplate ();

//Set the template
$login->identify_template ("login_grad.html");

if ($msg != "") {//If there is an error to report

	if (!($errormsg = $msg_error[$msg])) {//If the errormsg can not be found
		$errormsg = "An unknown error has occured.";
	}

	//Create a new page for the HTML template class
	$msgtable = new htmltemplate ();

	//Set the template
	$msgtable->identify_template ("error_table.html");

	//Set page title
	$msgtable->set_parameter ("ERROR", "Login failed");
	$msgtable->set_parameter ("ERROR_TEXT", $errormsg);

	//Send HTML to page
	$login->set_parameter ("LOGIN_ERROR", $msgtable->create_page());
} else {
	$login->set_parameter ("LOGIN_ERROR", "");
}

//Create the page
echo $login->create_page();

exit;
}

//Create a new page for the HTML template class
$page = new htmltemplate ();

//Set the template
$page->identify_template ("template.html");

//Delete content, make space for new
$content = "";

//Main content
if ($user_logged_in == TRUE) {
	require_once ("gradparty_inc_links.php");

	if ($user_level_logged >= 2) {
		require_once ("gradparty_inc_links_admin.php");
	}

	[b]require_once ("gradparty_inc_$incpage.php");[/b]
} else {
	$content .= "You are not logged in";
}

//Send content to page
$page->set_parameter ("MAIN_CONTENT", $content);

//Delete content, make space for new
$content = "";

//Create the page
echo $page->create_page();
?>

 

I am not super profficient in PHP/MySQL, but i do know a bit. I did however not write the above code/page.

 

If anyone could help me resolve this problem i would be very greatful

 

If its of any interest this is what the mysql database looks like:

 

  `guest_id` int(10) unsigned NOT NULL auto_increment,
 `guest_name` varchar(255) NOT NULL default '',
 `guest_surname` varchar(255) NOT NULL default '',
 `guest_inviter` int(11) NOT NULL default '0',

 

I also tried running all of the above mysql queries in phpmyadmin and they all worked. Ill upload all the code if anyone feels like trying it out on their webserver. If anyone has any other guest list scripts that i could use please tell me

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.