Jump to content

[SOLVED] Not Adding Value To UL


Xtremer360

Recommended Posts

Nothing happens when the button is clicked to add a new character name to the UL.

 

This is in my ajax.js

function WrestlerList()
{
var addWrestler = document.getElementById("character_selection").value
if (addWrestler) {
// Here we append a new wrestler to your hidden field using a comma
document.getElementById("chars").value += addWrestler+",";
// Continue your original functionality
document.getElementById("characterlist").innerHTML += "<li>" + 
addWrestler + "</li>";
return WrestlerList;
}
}

 

backstagefunctions.php

print '<script type="text/javascript" src="ajax.js"></script>';
   print '<h2 class="backstage">Characters<br /><br />';
   print '<select name="characterid" class="dropdown" id="character_selection">';
   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 type="hidden" id="chars" name="chars" value=""><input type="button" value="Add" onclick="WrestlerList()" class="button"></h2><br />';
   print '<ul id="characterlist"></ul><br /></form>';

 

 

Link to comment
Share on other sites

works for me:

 

<script>
function WrestlerList()
{
var addWrestler = document.getElementById("character_selection").value
if (addWrestler) {
// Here we append a new wrestler to your hidden field using a comma
document.getElementById("chars").value += addWrestler+",";
// Continue your original functionality
document.getElementById("characterlist").innerHTML += "<li>" +
addWrestler + "</li>";
return WrestlerList;
}
}
</script>
<?php
//   print '<script type="text/javascript" src="ajax.js"></script>';
   print '<h2 class="backstage">Characters<br /><br />';
   print '<select name="characterid" class="dropdown" id="character_selection">';
   print '<option value="">- Select -</option>';
//   $query = 'SELECT charactername FROM characters';
//   $result = mysql_query ( $query );
//   while ( $row = mysql_fetch_assoc ( $result ) ) {
      print "<option value=\"Foobar1\">Foobar1</option>\r";
      print "<option value=\"Foobar2\">Foobar2</option>\r";
      print "<option value=\"Foobar3\">Foobar3</option>\r";
      print "<option value=\"Foobar4\">Foobar4</option>\r";
//   }
   print '</select>  <input type="hidden" id="chars" name="chars" value=""><input type="button" value="Add" onclick="WrestlerList()" class="button"></h2><br />';
   print '<ul id="characterlist"></ul><br /></form>';
?>

Link to comment
Share on other sites

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"><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 '<select name="characterid" class="dropdown" id="character_selection">';
   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 type="hidden" id="chars" name="chars" value=""><input type="button" value="Add" onclick="WrestlerList()" class="button"></h2><br />';
   print '<ul id="characterlist"></ul><br /></form>';  
print '<h2 class="backstage"><form method="post"><input type="submit" value="Return to Main Menu" class="button200"></form></h2>';
}

 

var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid)
{
url = 'backstagefunctions.php?f=' + url;

var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject)
{
	// if IE
	try
	{
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
	} 
	catch (e)
	{
		try
		{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch (e)
		{
		}
	}
}
else
{
	return false
}

page_request.onreadystatechange=function()
{
	loadpage(page_request, containerid)
}

page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid)
{
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs()
{
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++)
{
	var file=arguments[i]
	var fileref=""
	if (loadedobjects.indexOf(file)==-1)
	{ 
		//Check to see if this object has not already been added to page before proceeding
		if (file.indexOf(".js")!=-1)
		{
			//If object is a js file
			fileref=document.createElement('script')
			fileref.setAttribute("type","text/javascript");
			fileref.setAttribute("src", file);
		}
		else if (file.indexOf(".css")!=-1)
		{
			//If object is a css file
			fileref=document.createElement("link")
			fileref.setAttribute("rel", "stylesheet");
			fileref.setAttribute("type", "text/css");
			fileref.setAttribute("href", file);
		}
	}
	if (fileref!="")
	{
		document.getElementsByTagName("head").item(0).appendChild(fileref)
		loadedobjects+=file+" " //Remember this object as being already added to page
	}
}
}
function WrestlerList()
{
var addWrestler = document.getElementById("character_selection").value
if (addWrestler) {
// Here we append a new wrestler to your hidden field using a comma
document.getElementById("chars").value += addWrestler+",";
// Continue your original functionality
document.getElementById("characterlist").innerHTML += "<li>" +
addWrestler + "</li>";
return WrestlerList;
}
}

Link to comment
Share on other sites

<h1 class="backstage">Handler Management</h1><br /><h2 class="backstage">Add New Handler Account</h2
><br /><form name="addhandler" method="post" action="backstage.php" id="addhandler"><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="account" class="selection"><option value="0">- Select -</option
><option value="Active">Active</option><option value="Inactive">Inactive</option></select></td></tr>
<tr><td class="rowheading">Administrator:</td><td class="row3"><select name="admin" 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="addhandler">
<br /><input type="hidden" name="action" value="handlers"><input type="submit" value="Return to Handler
List" class="button200"><br /><br /><script type="text/javascript" src="ajax.js"></script><h2 class
="backstage">Characters<br /><br /><select name="characterid" class="dropdown" id="character_selection"
><option value="">- Select -</option><option value="Anguish">Anguish</option>
<option value="Pyro">Pyro</option>
</select>  <input type="hidden" id="chars" name="chars" value=""><input type="button" value
="Add" onclick="WrestlerList()" class="button"></h2><br /><ul id="characterlist"></ul><br /></form><h2
class="backstage"><form method="post"><input type="submit" value="Return to Main Menu" class="button200"
></form></h2>

Link to comment
Share on other sites

Okay so I ran a test on my form to have it go into the DB and this came up:

 

Could not add the entry because: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 'Anguish,')' at line 1". The query was INSERT INTO `users` (`username`, `password`, `surname`, `firstname`, `email`, `aim`, `msn`, `forumid`, `status`, `admin`,`characters`) VALUES ('Testing', 'klad;jf', 'l;jdafl;','kljl;kj', 'k;lj', 'k', ';ljk', ';l', 'Active', '2',, 'Anguish,').

 

    //Form was submitted - determine the form
    if ( isset ( $_POST['edithandler'] ) ) {
        // 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 = "UPDATE 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 edited.</p>';
        } else {
            print '<p>Could not add the entry because: <b>"' . mysql_error() . '"</b>. The query was '.$query.'.</p>';
        }
        
        //mysql_close ();
    
    }

Link to comment
Share on other sites

oops wrong one sorry

 

//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`,`characters`) VALUES ('".addslashes($login)."', '".addslashes($p)."', '".addslashes($surname)."','".addslashes($firstname)."', '".addslashes($email)."', '".addslashes($aim)."', '".addslashes($msn)."', '".addslashes($forumid)."', '".addslashes($account)."', '".addslashes($admin)."',, '".addslashes($_POST['chars'])."')"; 
        
        // 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 ();
    
    }

Link to comment
Share on other sites

here is an extra comma before the last value:

 

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

Link to comment
Share on other sites

you are not getting the md5() value because you assign $p AFTER the md5()...change the order around:

//Form was submitted - determine the form
    if ( isset ( $_POST['addhandler'] ) ) {
        // Define the query.
        $login = $_POST['login'];
        $p = md5($_POST['password']);
//        $password = md5($p); //This isn't needed any more
        $surname = $_POST['surname'];
        $firstname = $_POST['firstname'];
        $email = $_POST['email'];
...

 

and what SHOULD the field for 'characters' look like then?

Link to comment
Share on other sites

//Form was submitted - determine the form
    if ( isset ( $_POST['addhandler'] ) ) {
        // Define the query.
        $login = $_POST['login'];
        $p = md5($_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'];
        $characters = preg_replace('/,$/','',$_POST['chars']);
       
        $query = "INSERT INTO `users` (`username`, `password`, `surname`, `firstname`, `email`, `aim`, `msn`, `forumid`, `status`, `admin`,`characters`) VALUES ('".addslashes($login)."', '".addslashes($p)."', '".addslashes($surname)."','".addslashes($firstname)."', '".addslashes($email)."', '".addslashes($aim)."', '".addslashes($msn)."', '".addslashes($forumid)."', '".addslashes($account)."', '".addslashes($admin)."',, '".addslashes($characters)."')";
        

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.