Page 1 of 1

Adding UL to Insert Tag

Posted: Tue Jan 20, 2009 1:08 pm
by CoolAsCarlito
My mysql insert query works fine however what I want to do is add all the value strings inside of the UL from the bottom of backstagefunctions.php file to my mysql insert query so it'll insert those values into the DB field. How do I do that?


AjaxHandler.php

Code: Select all

//Form was submitted - determine the form
    if ( isset ( $_POST['addhandler'] ) ) {
        // 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 ();
   
    }
backstagefunctions.php

Code: Select all

function addhandler() {
   print '<h1 class="backstage">Handler Management</h1><br />';
   print '<h2 class="backstage">Add New Handler Account</h2><br />';
   print '<form name="addhandler" method="post" action="backstage.php" id="addhandler">';
   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="submit" value="Save Handler" class="button" name="addhandler"></form><br />';
   print '<input type="hidden" name="action" value="handlers"><input type="submit" value="Return to Handler List" class="button200"><br /><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>&nbsp;&nbsp;<input name="submit" type="submit" value="Add" class="button"></form></h2><br />';
   print '<ul id="characterlist"></ul><br />'; 
   print '<h2 class="backstage"><form method="post"><input type="submit" value="Return to Main Menu" class="button200"></form></h2>';
}

Re: Adding UL to Insert Tag

Posted: Tue Jan 20, 2009 1:11 pm
by Burrito

Code: Select all

 
theUL = document.getElementById("characterlist");
if(theUL.innerHTML == "")
  // nothing here don't insert
else
  // something here, insert it
 

Re: Adding UL to Insert Tag

Posted: Tue Jan 20, 2009 1:17 pm
by CoolAsCarlito
I meant into my mysql insert tag

Re: Adding UL to Insert Tag

Posted: Tue Jan 20, 2009 1:19 pm
by Burrito
I don't know how you're doing your ajax call, but if you're passing the UL value either way, then check it's existence on the server side doing basically the same thing I've done above.

Re: Adding UL to Insert Tag

Posted: Tue Jan 20, 2009 4:57 pm
by CoolAsCarlito
My mysql insert query works fine however what I want to do is add all the value strings inside of the UL from the bottom of backstagefunctions.php file to my mysql insert query so it'll insert those values into the DB field. How do I do that?

Re: Adding UL to Insert Tag

Posted: Tue Jan 20, 2009 4:59 pm
by Burrito
either get the value client side and pass it to a post argument string (my first post), or check it server side and add it to your insert statement (my second post).