Jump to content

[SOLVED] Multiple Requests


Xtremer360

Recommended Posts

I have this function among many that houses forms. I'm also using an ajax page that is supposed to deal with form's entries and insert everything into my DB and I don't know how to separate the different requests on the ajax page so that it can do what the correct request is.

 

Function Form 1

 

function newhandler() {
if (isset ( $_POST ['submit2'] )) { // Handle the form.
	// Define the query.
	$password = md5($p); // Currently $p does not have a value
	$login = $_POST['login'];
	$p = $_POST['password'];
	$surname = $_POST['surname'];
	$firstname = $_POST['firstname'];
	$email = $_POST['email'];
	$aim = $_POST['aim'];
	$msn = $_POST['msn'];
	$forumid = $_POST['forumid'];
	$account = $_POST['account'];
	$admin = $_POST['admin'];

	$query = "INSERT INTO users (username, password, surname, firstname, email, aim, msn, forumid, status, admin) VALUES ('".addslashes($login)."', '".addslashes($p).", '".addslashes($surname).",'".addslashes($firstname).", '".addslashes($email).", '".addslashes($aim).", '".addslashes($msn).", '".addslashes($forumid).", '".addslashes($account).", '".addslashes($admin)."')";

	// Execute the query.
	if (@mysql_query ( $query )) {
		print '<p>The handler has been added.</p>';
	} else {
		print '<p>Could not add the entry because: <b>"' . mysql_error() . '"</b>. The query was '.$query.'.</p>';
	}

	mysql_close ();

}

print '<h1 class="backstage">Handler Management</h1><br />';
print '<h2 class="backstage">Add New Handler Account</h2><br />';
print '<form name="newhandler" method="post" action="">';
print '<table width="100%" class="table2">';
print '<tr>';
print '<td width="120" class="rowheading">Username:</td><td class="row3"><input type="text" name="login" class="fieldtext490"></td>';
print '</tr>';
print '<tr>';
print '<td class="rowheading">Password:</td><td class="row3"><input type="password" name="password" class="fieldtext490"></td>';
print '</tr>';
print '<tr>';
print '<td class="rowheading">Surname:</td><td class="row3">';
print '<input type="text" name="surname" class="fieldtext490"></td>';
print '</tr>';
print '<tr>';
print '<td class="rowheading">Firstname:</td>';
print '<td class="row3"><input type="text" name="firstname" class="fieldtext490"></td>';
print '</tr>';
print '<tr>';
print '<td class="rowheading">Email:</td>';
print '<td class="row3"><input type="text" name="email" class="fieldtext490"></td>';
print '</tr>';
print '<tr>';
print '<td class="rowheading">AIM:</td>';
print '<td class="row3"><input type="text" name="aim" class="fieldtext490"></td>';
print '</tr>';
print '<tr>';
print '<td class="rowheading">MSN:</td>';
print '<td class="row3"><input type="text" name="msn" class="fieldtext490"></td>';
print '</tr>';
print '<tr>';
print '<td class="rowheading">Forum ID:</td>';
print '<td class="row3"><input type="text" name="forumid" class="fieldtext490"></td>';
print '</tr>';
print '<tr>';
print '<td class="rowheading">Account:</td>';
print '<td class="row3"><select name="account" class="selection"><option value="0">- Select -</option>';
print '<option value="Active">Active</option><option value="Inactive">Inactive</option>';
print '</select></td>';
print '</tr>';
print '<tr>';
print '<td class="rowheading">Administrator:</td>';
print '<td class="row3"><select name="admin" class="selection"><option value="0">- Select -</option>';
print '<option value="2">No</option><option value="1">Yes</option>';
print '</select></td>';
print '</tr>';
print '</table><br />';
print '<input type="button" value="Save Handler" class="button" onclick="sendToServer()"></form><br />';
print '<input type="hidden" name="action" value="handlers"><input type="submit" value="Return to Handler List" class="button200"><br />';
print '<script type="text/javascript" src="ajax.js"></script>';
   print '<h2 class="backstage">Characters<br /><br />';
   print '<form method=post name="addwrestler" onsubmit="return WrestlerList(this);"><select name="characterid" class="dropdown">';
   print '<option value="">- Select -</option>';
   $query = 'SELECT charactername FROM characters';
   $result = mysql_query ( $query );
   while ( $row = mysql_fetch_assoc ( $result ) ) {
      print "<option value=\"".$row['charactername']."\">".$row['charactername']."</option>\r";
   }
   print '</select>  <input name="submit" type="submit" value="Add" class="button"></form></h2><br />';
   print '<ul id="characterlist"></ul>';  
print '<h2 class="backstage"><form method="post"><input type="submit" value="Return to Main Menu" class="button200"></form></h2>';
}

 

 

The first grouping of variables is dealing with the function form one as shown above. And the second grouping is supposed to deal with another form I have.

 

Ajax Page

<?php


$login = $_GET["login"];
$password = $_GET["password"];
$surname = $_GET["surname"];
$firstname = $_GET["firstname"];
$email = $_GET["email"];
$aim = $_GET["aim"];
$msn = $_GET["msn"];
$forumid = $_GET["forumid"];
$account = $_GET["account"];
$admin = $_GET["admin"];


$charactername = $_GET ['charactername'];
$username = $_GET ['username'];
$posername = $_GET ['posername'];
$style = $_GET ['style'];
$gender = $_GET ['gender'];
$status = $_GET ['status'];
$division = $_GET ['division'];
$alignment = $_GET ['alignment'];
$sort = $_GET ['sort'];


?>

Link to comment
https://forums.phpfreaks.com/topic/140614-solved-multiple-requests/
Share on other sites

Let me redescibe it so you can see if that is what I need.

 

Main File=backstage.php (houses login and cp)

 

Functions= backstagefunctions.php (houses what each option does inside of cp.

 

Ajax Page= (holds) the variables so that the forms on the functions can be inserted into the DB once submitted

 

I am not completely understanding what you are describing.

 

Let me paraphrase what I *think* you are doing. You have a PHP page (backstage.php) which in turn has numerous function on the page (backstagefunctions.php). There is also an AJAX page (whatever that means) which holds some variables. I don't know what you mean by calling that an AJAX page since it doesn't DO anything but set some variables. I would assume the term "AJAX page" to mean a PHP page that is called through an AJAX request and performs some actions.

 

OK, on the main page there must be some actions which trigger an AJAX request. I *think* you have multiple forms on the backstage.php page and depending on which form is submitted (through AJAX) you want different processes to occur.

 

If what I stated above is correct, there are two solutions that come to mind. 1) Have the "onsubmit" action for each form call a different page through AJAX to process the request. The "form variables" could then be included within each of those processing pages. 2) Continue to have a single processing page that is called through AJAX, but add a parameter to the request based upon the form (e.g. $_GET['mode']) so the processing page can determine which functions and variables to use.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.