Jump to content

Ajax Issue or PHP Scripting Issue?


Xtremer360

Recommended Posts

The idea I want here is when the user click on a character name from the drop down select bar at the bottom of the the form under case 1 and hits Add it is supposed to add it as a new LI in the UL that's under the drop down. Also what I woudl like to do is when the user as chosen all of the characters they want to I would like to insert the data into the insert tag inside my function at the bottom of this code strip and take the first character selected and put it into the insert with the column of default_char_id and default_news_id.

 

Right now when you click the right submit button next to the drop down all it does is go back to the default page I have set up.

 

<?php 
   $e = <<<here
       <script src="./jscripts/scriptaculous/prototype.js" type="text/javascript"></script>
      <script src="./jscripts/scriptaculous/scriptaculous.js" type="text/javascript"></script>
      <script type="text/javascript" src="./jscripts/ajax.js"></script>
here;
   switch ($_REQUEST['option']) {
      case 0:
         echo $e;
         ?>
            <h1 class=backstage>Handler Management</h1><br />
            <h2 class="backstage">Handlers :: <a href="#" onclick="ajaxpage('backstage_libs/handler.php?option=1', 'content'); return false;">Add New</a></h2><br />
            <table width="100%" class="table1">
                <tr class="rowheading">
                    <td width="30"> </td>
                    <td align="center">Username</td>
                    <td align="center">Surname</td>
                    <td align="center">First Name</td>
                    <td align="center">E-Mail</td>
                </tr>
            <?php   
            $query = "SELECT * FROM  efed_handler";
            $result = mysql_query ( $query ); // Run The Query
    
            if ($result) {
            $i = 0;
            while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) {
               $sClass = 'row2';
               if ($i++ % 2) $sClass = 'row1';
               printf ( "<tr class=\"%s\">", $sClass );
                    print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"ajaxpage('backstage_libs/handler.php?option=2', 'content'); return false;\">Edit</a></td>";
                    printf ( "<td valign=\"top\" align=\"center\">%s</td>", $row [login] );
                    printf ( "<td valign=\"top\" align=\"center\">%s</td>", $row [surname] );
                    printf ( "<td valign=\"top\" align=\"center\">%s</td>", $row [firstname] );
                    printf ( "<td valign=\"top\" align=\"center\">%s</td>", $row [email] );
                    echo'</tr>';
                }
            echo '</table><br>';
         } else {
            echo '<span>There are no match types.</span><br />';
         }
         returnmain();
      break;
      case 1:
         echo $e;
            require_once('../backstageconfig.php');
         require_once('../backstagefunctions.php');
         ?>
            <h1 class="backstage">Handler Management</h1><br />
            <h2 class="backstage">Add New Handler Account</h2><br />
            <form name="addnewhandler" method="post">
                <table width="100%" class="table2">
                    <tr>
                        <td width="120" class="rowheading">Username:</td><td class="row3"><input type="text" name="login" class="fieldtext490"></td>
                    </tr>
                    <tr>
                        <td class="rowheading">Password:</td><td class="row3"><input type="password" name="password" class="fieldtext490"></td>
                    </tr>
                    <tr>
                        <td class="rowheading">Surname:</td><td class="row3">
                        <input type="text" name="surname" class="fieldtext490"></td>
                    </tr>
                    <tr>
                        <td class="rowheading">Firstname:</td>
                        <td class="row3"><input type="text" name="firstname" class="fieldtext490"></td>
                    </tr>
                    <tr>
                        <td class="rowheading">Email:</td>
                        <td class="row3"><input type="text" name="email" class="fieldtext490"></td>
                    </tr>
                    <tr>
                        <td class="rowheading">AIM:</td>
                        <td class="row3"><input type="text" name="aim" class="fieldtext490"></td>
                    </tr>
                    <tr>
                        <td class="rowheading">MSN:</td>
                        <td class="row3"><input type="text" name="msn" class="fieldtext490"></td>
                    </tr>
                    <tr>
                        <td class="rowheading">Forum ID:</td>
                        <td class="row3"><input type="text" name="forumid" class="fieldtext490"></td>
                    </tr>
                    <tr>
                        <td class="rowheading">Account:</td><td class="row3">
                        <select name="enabled" class="selection">
                        <option value="0">- Select -</option>
                        <?php
                        $query = 'SELECT name FROM efed_list_status';
                        $result = mysql_query ( $query );
                        while ( $row = mysql_fetch_assoc ( $result ) ) 
                        {
                            print "<option value=\"".$row['name']."\">".$row['name']."</option>\r";
                        }
                        ?>
                        </select></td>
                    </tr>
                    <tr>
                        <td class="rowheading">Administrator:</td><td class="row3">
                        <select name="isadmin" class="selection">
                        <option value="0">- Select -</option>
                        <option value="2">No</option><option value="1">Yes</option>
                        </select></td>
                    </tr>
                </table><br />
                <input type="submit" value="Save Handler" class="button" name="submit"></form><br /><br />
                <input type="submit" value="Return to Handler List" class="button200"><br /><br />
                <h2 class="backstage">Characters<br /><br /><form method="post"><select name="characterid" class="dropdown">
                <option value="0">- Select -</option>
                <?php
                $query = 'SELECT charactername FROM efed_bio';
                $result = mysql_query ( $query );
                while ( $row = mysql_fetch_assoc ( $result ) ) 
                {
                print "<option value=\"".$row['charactername']."\">".$row['charactername']."</option>\r";
                }
                ?>
                </select>  <input type="hidden" id="chars" name="chars" value=""><input type="submit" value="Add" class="button"></form></h2><br />
                <ul id="characterlist"></ul><br />
            </form>
            <?php
            returnmain();
        break;
      case 2:
         echo $e;
            require_once('../backstageconfig.php');
         require_once('../backstagefunctions.php');
         ?>
            <h1 class=backstage>Handler Management</h1><br />
            <h2 class=backstage>Edit Handler Details</h2><br />
            <form name="edithandler" method="post">
                <table width="100%" class="table2">
                    <tr>
                        <td width=120 class=rowheading>Username:</td><td class=row3><input type=text name=login class=fieldtext490 value=""></td>
                    </tr>
                    <tr>
                        <td class=rowheading>Password:</td><td class=row3><input type=password name=password class=fieldtext490 onfocus="this.select()" value=""></td>
                    </tr>
                    <tr>
                        <td class=rowheading>Surname:</td><td class=row3>
                        <input type=text name=surname class=fieldtext490 value=""></td>
                    </tr>
                    <tr>
                        <td class=rowheading>Firstname:</td>
                        <td class=row3><input type=text name=firstname class=fieldtext490 value=""></td>
                    </tr>
                    <tr>
                        <td class=rowheading>Email:</td>
                        <td class=row3><input type=text name=email class=fieldtext490 value=""></td>
                    </tr>
                    <tr>
                        <td class=rowheading>AIM:</td>
                        <td class=row3><input type=text name=aim class=fieldtext490 value=""></td>
                    </tr>
                    <tr>
                        <td class=rowheading>MSN:</td>
                        <td class=row3><input type=text name=msn class=fieldtext490 value=""></td>
                    </tr>
                    <tr>
                        <td class=rowheading>Forum ID:</td>
                        <td class=row3><input type=text name=forumid class=fieldtext490 value=""></td>
                    </tr>
                    <tr>
                        <td class=rowheading>Account:</td>
                        <td class="row3"><select name="enabled" class="selection"><option value="0">- Select -</option>
                        <?php
                        $query = 'SELECT name FROM efed_list_status';
                        $result = mysql_query ( $query );
                        while ( $row = mysql_fetch_assoc ( $result ) ) 
                        {
                            print "<option value=\"".$row['name']."\">".$row['name']."</option>\r";
                        }
                        ?>
                        </select></td>
                    </tr>
                    <tr>
                        <td class=rowheading>Administrator:</td>
                        <td class=row3>
                        <select name=isadmin class=selection>
                        <option value="0">- Select -</option>
                        <option value=1>No</option><option value=0>Yes</option>
                        </select></td>
                    </tr>
                    <tr>
                        <td class=rowheading>Default Character:</td>
                        <td class=row3></td>
                    </tr>
                </table><br />
                <input type=checkbox name=deletehandler> <span class=table1heading>Delete Handler?</span><br /><br />
                <input type="submit" value="Save Handler" class="button" name="submit2"></form><br />
                <form method=POST><input type=submit value="Return to Handler List" class=button200></form><br />
            <h2 class=backstage>Characters<br /><br />
            <form method=post name="addwrestler" onsubmit="return WrestlerList(this);">
                <select name=characterid class=dropdown>
                <option value=0>- Select -</option>
                <?php
                $query = 'SELECT charactername FROM efed_bio';
                $result = mysql_query ( $query );
                while ( $row = mysql_fetch_assoc ( $result ) ) 
                {
                    print "<option value=\"".$row['charactername']."\">".$row['charactername']."</option>\r";
                }
                ?>
                </select>  
                    <input type="hidden" id="chars" name="chars" value="">
                <input type=submit value="Add" class=button></form></h2><br />
                <ul id="characterlist">
                </ul><br />
            </form>   
            <?php
         returnmain();
      break;
   }
   function handler() {
      if ((!empty($_POST['newadded']))) {
         $password = md5($password);
            $login = mysql_real_escape_string($_POST['login']);
            $p = mysql_real_escape_string($_POST['password']);
            $surname = mysql_real_escape_string($_POST['surname']);
            $firstname = mysql_real_escape_string($_POST['firstname']);
            $emial = mysql_real_escape_string($_POST['email']);
            $aim = mysql_real_escape_string($_POST['aim']);
            $msn = mysql_real_escape_string($_POST['msn']);
            $forumid = mysql_real_escape_string($_POST['forumid']);
            $isadmin = mysql_real_escape_string($_POST['isadmin']);
            $enabled = mysql_real_escape_string($_POST['enabled']);
         $query = "INSERT INTO `efed_handler` (surname,firstname,isadmin,login,password,enabled,aim,msn,forumid,email,fed_id) VALUES ('".$surname."','".$firstname."','".$isadmin."','".$login."','".$password."','".$enabled."','".$aim."','".$msn."','".$forumid."','".$email."',1)";
         if (mysql_query($query)) {
            //success
         } else {
            //fail
         }
      }
   }
?>


<script type="text/javascript" language="javascript">
function WrestlerList()
    {
      var addWrestler = document.getElementById("character_selection").value
      if (addWrestler)
        {
      document.getElementById("chars").value += addWrestler+",";
      var li = document.createElement('li');
      li.innerHTML = addWrestler;
      document.getElementById("characterlist").appendChild(li);
        }
    }
</script>     

Link to comment
Share on other sites

Need to add "return false" to the js function to keep the form from submitting to itself. Like:

function WrestlerList()
    {
      var addWrestler = document.getElementById("character_selection").value
      if (addWrestler)
        {
          document.getElementById("chars").value += addWrestler+",";
          var li = document.createElement('li');
          li.innerHTML = addWrestler;
          document.getElementById("characterlist").appendChild(li);
        }
     return false;
    }

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.