Page 1 of 1

Error 1 in my ajax drop down

Posted: Thu Oct 23, 2008 6:02 pm
by CoolAsCarlito
What I'm wanting it to do is have it drop down with the show types and it's doing that but it doesn't go to the shownames table and load the shownames into the second drop down. It says Error 1 in in it's spot. What's wrong with my coding?


Ajax Page

Code: Select all

 
<?php
 
require('database.php');
 
if(isset($_GET['type']))
 
{
 
    $type = mysql_real_escape_string($_GET['type'],$link);
 
     $res = mysql_query("SELECT 'showname` FROM `shownames` WHERE `type` = '".$type."' ORDER BY showname") or die("ERROR 1");
     
    echo "<select id=\"names\" onChange=\"ajaxGetL();\">";
 
    while($list = mysql_fetch_assoc($res))
 
    {
 
        echo "<option value=\"".$list['showname']."\">".$list['showname']."</option>";
 
    }
 
    echo "</select>";
 
}
 
else if(isset($_GET['label']))
{
    $label = mysql_real_escape_string($_GET['label'],$link);
 
    $res = mysql_query("SELECT `showlabel` FROM `shows` WHERE `showname` = '".$label."' ORDER BY `showlabel` DESC LIMIT 1;") or die("ERROR 1");
    
    $list = mysql_fetch_assoc($res);
    
    echo $list['showlabel']+1;
}
 
?> 
 
PHP Page

Code: Select all

<html>
 
<head>
 
<title>Untitled Document</title>
 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 
<script type="text/javascript">
 
function ajaxGet()
 
{
 
    var xmlHttp;
 
    try
 
    {
 
        // Firefox, Opera 8.0+, Safari
 
        xmlHttp=new XMLHttpRequest();
 
    }
 
    catch (e)
 
    {
 
        // Internet Explorer
 
        try
 
        {
 
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
 
        }
 
        catch (e)
 
        {
 
            try
 
            {
 
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
 
            }
 
            catch (e)
 
            {   
 
                alert("Your browser does not support AJAX!");
 
                return false;
 
            }
 
        }
 
    }
 
    xmlHttp.onreadystatechange=function()
 
    {
 
        if(xmlHttp.readyState==4)
 
        {
 
            document.getElementById('shownam').innerHTML = xmlHttp.responseText;
            ajaxGetL();
 
        }
 
    }
 
    //alert("Selected: " + document.getElementById("ajax1").value);
 
    xmlHttp.open("GET","showAjax.php?type=" + document.getElementById("ajax1").value + "&rand=" + Math.random(),true);
 
    xmlHttp.send(null);
 
}
 
function ajaxGetL()
 
{
    //alert("CALLED");
    var xmlHttp;
 
    try
 
    {
 
        // Firefox, Opera 8.0+, Safari
 
        xmlHttp=new XMLHttpRequest();
 
    }
 
    catch (e)
 
    {
 
        // Internet Explorer
 
        try
 
        {
 
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
 
        }
 
        catch (e)
 
        {
 
            try
 
            {
 
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
 
            }
 
            catch (e)
 
            {   
 
                alert("Your browser does not support AJAX!");
 
                return false;
 
            }
 
        }
 
    }
 
    xmlHttp.onreadystatechange=function()
 
    {
 
        if(xmlHttp.readyState==4)
 
        {
 
            document.getElementById('label').value = xmlHttp.responseText;
 
        }
 
    }
 
    //alert("Selected: " + document.getElementById("ajax1").value);
 
    xmlHttp.open("GET","showAjax.php?label=" + document.getElementById("names").value + "&rand=" + Math.random(),true);
 
    xmlHttp.send(null);
 
}
 
</script>
 
</head>
 
 
 
<body>
 
<?php
 
 
 
/* setupshow.php */
 
/* This form after submission takes the results of the form and makes a new show ready for adding matches. */
 
require ('database.php');
 
print '<center><caption><strong>Create A Show</strong></caption></center>';
 
print '<table border="1" align="center" style="margin: auto; width: 60%;">';
 
print '<SCRIPT LANGUAGE="JavaScript" SRC="CalendarPopup.js"></SCRIPT>';
 
print '<SCRIPT LANGUAGE="JavaScript"> var cal = new CalendarPopup(); </SCRIPT>';
 
print '<form action="setupshow.php" method="post" name="form1">';
 
print '<tr><td>Weekly Show or Pay-Per View:</td><td><select name="type" id="ajax1" onChange="ajaxGet();"><option value="">Select a Show Type</option>';
 
                 $query = 'SELECT type FROM showtypes ORDER BY type';
 
                $result = mysql_query($query);
 
            while ($row = mysql_fetch_assoc($result)){
 
                    print "<option value=\"{$row['type']}\">{$row['type']}</option>\r";
 
                }           
 
print '</select></td></tr>';
 
print "<tr><td>Show Name:</td><td><div id=\"shownam\"><select id=\"names\" onChange=\"ajaxGetL();\"></select></div></td></tr>";
 
print '<tr><td>Show Label:</td><td><input name="showlabel" id="label" type="text" readonly="true" size="5"></td></tr>';
 
print '<tr><td>Location:</td> ';
print '<td><input name="location" type="text"></td></tr>';
print '<tr><td>Arena:</td> ';
print '<td><input name="arena" type="text"></td></tr>';
print '<tr><td>Date:</td><td><input type="text" name="date" readonly="readonly" /> <a href="#" onClick="cal.select(document.forms[\'form1\'].date,\'anchor1\',\'MM/dd/yyyy\'); return false;"NAME="anchor1" ID="anchor1">Date Selector</a></td></tr>';
 
print '<tr><th colspan=2><input name="submit" type="submit" value="Submit"><input name="sumbitted" type="hidden" value="TRUE"></th></tr></table></form><br><br><br>';
 
print '<center><caption><strong>List of shows</strong></caption></center>';
print '<table width="60%" border="1" align="center">';
print '<tr><th align="center">Show Name</th><th align="center">Show Label</th><th align="center">Location</th><th align="center">Arena</th><th align="center">Date</th><th align="center">Edit</th><th align="center">Delete</th></tr>';
 
if(!isset($_GET['action']) && !isset($_POST['name']))
{
   //Define the query
   $query = "SELECT * FROM shows";
   if ($r = mysql_query ($query)) // Run the query.
   {
       if (mysql_num_rows($r) > 0)
       {
           // Retrieve and print every record
           while ($row = mysql_fetch_array ($r))
           {
              print '<tr><td align="center">'.$row['showname'].'</td><td align="center">'.$row['showlabel'].'</td><td align="center">'.$row['location'].'</td><td align="center">'.$row['arena'].'</td><td align="center">'.$row['date'].'</td><td align="center"><a href="addshowname.php?action=edit&id='.$row['id'].'"><center>Edit</center></a></td><td align="center"><a href="addshowname.php?action=delete&id='.$row['id'].'">Delete</a></td></tr>';
           }
        }else{
           print "<center>No shows</center>\n";
        }
   }else{
      die ('<p>Could not retrieve the data because <b>' . mysql_error() . '</b>. The query was '."$query.".'</p>');
   } //End of query IF
   print '</table>';
}
?> 
 
</body>
 
</html>