Solved

AJAX Interactive Communication with a MySQL Database

Posted on 2010-08-20
15
467 Views
Last Modified: 2013-12-13
I have a PHP form set up in Dreamweaver with dynamic drop downs updating from a MySQL database. I would like additional information from the database displayed on the page depending on one of the dropdown selections.

Someone pointed me to

http://www.w3schools.com/PHP/php_ajax_database.asp

which displays the functionality I need. I am having trouble implementing it however and no data is being pulled from the database.

Attached is the code for the main page (I will attach the getuser.php as described by the link above on next post).

A table header appears as expected on drop down selection but no data populates under it and no error comes up.
<?php require_once('Connections/***.php'); ?>

<?php

//initialize the session

if (!isset($_SESSION)) {

  session_start();

}



// ** Logout the current user. **

$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";

if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){

  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);

}



if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){

  //to fully log out a visitor we need to clear the session varialbles

  $_SESSION['MM_Username'] = NULL;

  $_SESSION['MM_UserGroup'] = NULL;

  $_SESSION['PrevUrl'] = NULL;

  unset($_SESSION['MM_Username']);

  unset($_SESSION['MM_UserGroup']);

  unset($_SESSION['PrevUrl']);

	

  $logoutGoTo = "logout.php";

  if ($logoutGoTo) {

    header("Location: $logoutGoTo");

    exit;

  }

}

?>

<?php

if (!isset($_SESSION)) {

  session_start();

}

$MM_authorizedUsers = "";

$MM_donotCheckaccess = "true";



// *** Restrict Access To Page: Grant or deny access to this page

function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 

  // For security, start by assuming the visitor is NOT authorized. 

  $isValid = False; 



  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 

  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 

  if (!empty($UserName)) { 

    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 

    // Parse the strings into arrays. 

    $arrUsers = Explode(",", $strUsers); 

    $arrGroups = Explode(",", $strGroups); 

    if (in_array($UserName, $arrUsers)) { 

      $isValid = true; 

    } 

    // Or, you may restrict access to only certain users based on their username. 

    if (in_array($UserGroup, $arrGroups)) { 

      $isValid = true; 

    } 

    if (($strUsers == "") && true) { 

      $isValid = true; 

    } 

  } 

  return $isValid; 

}



$MM_restrictGoTo = "loginfailed.php";

if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   

  $MM_qsChar = "?";

  $MM_referrer = $_SERVER['PHP_SELF'];

  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";

  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 

  $MM_referrer .= "?" . $QUERY_STRING;

  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);

  header("Location: ". $MM_restrictGoTo); 

  exit;

}

?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }



  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);



  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;    

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}



if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }



  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);



  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;    

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}



$colname_Recordset1 = "-1";

if (isset($_SESSION['client_ref'])) {

  $colname_Recordset1 = $_SESSION['client_ref'];

}

mysql_select_db($database_vscclients, $vscclients);

$query_Recordset1 = sprintf("SELECT * FROM client_table WHERE client_ref = %s", GetSQLValueString($colname_Recordset1, "text"));

$Recordset1 = mysql_query($query_Recordset1, $vscclients) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);



$colname_Recordset2 = "-1";

if (isset($_SESSION['client_ref'])) {

  $colname_Recordset2 = $_SESSION['client_ref'];

}

mysql_select_db($database_vscclients, $vscclients);

$query_Recordset2 = sprintf("SELECT * FROM animal_table WHERE client_ref = %s", GetSQLValueString($colname_Recordset2, "text"));

$Recordset2 = mysql_query($query_Recordset2, $vscclients) or die(mysql_error());

$row_Recordset2 = mysql_fetch_assoc($Recordset2);

$totalRows_Recordset2 = mysql_num_rows($Recordset2);



$colname_Recordset3 = "-1";

if (isset($_SESSION['client_ref'])) {

  $colname_Recordset3 = $_SESSION['client_ref'];

}

mysql_select_db($database_vscclients, $vscclients);

$query_Recordset3 = sprintf("SELECT * FROM clinical_table WHERE client_ref = %s", GetSQLValueString($colname_Recordset3, "text"));

$Recordset3 = mysql_query($query_Recordset3, $vscclients) or die(mysql_error());

$row_Recordset3 = mysql_fetch_assoc($Recordset3);

$totalRows_Recordset3 = mysql_num_rows($Recordset3);



$colname_Recordset4 = "-1";

if (isset($_GET['itemID'])) {

  $colname_Recordset4 = $_GET['itemID'];

}

mysql_select_db($database_vscclients, $vscclients);

$query_Recordset4 = sprintf("SELECT * FROM animal_table WHERE animal_pms_id = %s", GetSQLValueString($colname_Recordset4, "text"));

$Recordset4 = mysql_query($query_Recordset4, $vscclients) or die(mysql_error());

$row_Recordset4 = mysql_fetch_assoc($Recordset4);

$totalRows_Recordset4 = mysql_num_rows($Recordset4);



$colname_Recordset5 = "-1";

if (isset($_SESSION['practice_id'])) {

  $colname_Recordset5 = $_SESSION['practice_id'];

}

mysql_select_db($database_vscclients, $vscclients);

$query_Recordset5 = sprintf("SELECT * FROM practice_table WHERE practice_id = %s", GetSQLValueString($colname_Recordset5, "text"));

$Recordset5 = mysql_query($query_Recordset5, $vscclients) or die(mysql_error());

$row_Recordset5 = mysql_fetch_assoc($Recordset5);

$totalRows_Recordset5 = mysql_num_rows($Recordset5);



$colname_Recordset6 = "-1";

if (isset($_SESSION['practice_id'])) {

  $colname_Recordset6 = $_SESSION['practice_id'];

}

mysql_select_db($database_vscclients, $vscclients);

$query_Recordset6 = sprintf("SELECT * FROM branch_table WHERE practice_id = %s", GetSQLValueString($colname_Recordset6, "text"));

$Recordset6 = mysql_query($query_Recordset6, $vscclients) or die(mysql_error());

$row_Recordset6 = mysql_fetch_assoc($Recordset6);

$totalRows_Recordset6 = mysql_num_rows($Recordset6);



$colname_Recordset7 = "-1";

if (isset($_SESSION['practice_id'])) {

  $colname_Recordset7 = $_SESSION['practice_id'];

}

mysql_select_db($database_vscclients, $vscclients);

$query_Recordset7 = sprintf("SELECT * FROM surgery_table WHERE practice_id = %s", GetSQLValueString($colname_Recordset7, "text"));

$Recordset7 = mysql_query($query_Recordset7, $vscclients) or die(mysql_error());

$row_Recordset7 = mysql_fetch_assoc($Recordset7);

$totalRows_Recordset7 = mysql_num_rows($Recordset7);



$colname_parent = "-1";

if (isset($_SESSION['practice_id'])) {

  $colname_parent = $_SESSION['practice_id'];

}

mysql_select_db($database_vscclients, $vscclients);

$query_parent = sprintf("SELECT * FROM branch_table WHERE practice_id = %s", GetSQLValueString($colname_parent, "text"));

$parent = mysql_query($query_parent, $vscclients) or die(mysql_error());

$row_parent = mysql_fetch_assoc($parent);

$totalRows_parent = mysql_num_rows($parent);



$colname_child = "-1";

if (isset($_SESSION['practice_id'])) {

  $colname_child = $_SESSION['practice_id'];

}

mysql_select_db($database_vscclients, $vscclients);

$query_child = sprintf("SELECT * FROM veterinary_surgeon_table WHERE practice_id = %s ORDER BY surgery_date ASC", GetSQLValueString($colname_child, "text"));

$child = mysql_query($query_child, $vscclients) or die(mysql_error());

$row_child = mysql_fetch_assoc($child);

$totalRows_child = mysql_num_rows($child);



$colname_grandchild = "-1";

if (isset($_SESSION['practice_id'])) {

  $colname_grandchild = $_SESSION['practice_id'];

}

mysql_select_db($database_vscclients, $vscclients);

$query_grandchild = sprintf("SELECT * FROM veterinary_surgeon_table WHERE practice_id = %s", GetSQLValueString($colname_grandchild, "text"));

$grandchild = mysql_query($query_grandchild, $vscclients) or die(mysql_error());

$row_grandchild = mysql_fetch_assoc($grandchild);

$totalRows_grandchild = mysql_num_rows($grandchild);

?>





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>



<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Vet Surgery Connect: Contact Your Vet</title>











<script type="text/javascript">

function showUser(str)

{

if (str=="")

  {

  document.getElementById("txtHint").innerHTML="";

  return;

  } 

if (window.XMLHttpRequest)

  {// code for IE7+, Firefox, Chrome, Opera, Safari

  xmlhttp=new XMLHttpRequest();

  }

else

  {// code for IE6, IE5

  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

  }

xmlhttp.onreadystatechange=function()

  {

  if (xmlhttp.readyState==4 && xmlhttp.status==200)

    {

    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;

    }

  }

xmlhttp.open("GET","getuser.php?q="+str,true);

xmlhttp.send();

}

</script>













<?php

if ($row_grandchild)     {

  echo "<SC" . "RIPT>\n";

  echo "var WAJA = new Array();\n";



  $oldmainid = 0;

  $newmainid = $row_grandchild["branch_number"];

  if ($oldmainid == $newmainid)    {

    $oldmainid = "";

  }

  $n = 0;

  while ($row_grandchild)     {

    if ($oldmainid != $newmainid)     {

      echo "WAJA[".$n."] = new Array();\n";

      echo "WAJA[".$n."][0] = '".WA_DD_Replace($newmainid)."';\n";

      $m = 1;

    }



    echo "WAJA[".$n."][".$m."] = new Array();\n";

    echo "WAJA[".$n."][".$m."][0] = "."'".WA_DD_Replace($row_grandchild["vet_id"])."'".";\n";

    echo "WAJA[".$n."][".$m."][1] = "."'".WA_DD_Replace($row_grandchild["vet_name"])."'".";\n";



    $m++;

    if ($oldmainid == 0)      {

      $oldmainid = $newmainid;

    }

    $oldmainid = $newmainid;

    $row_grandchild = mysql_fetch_assoc($grandchild);

    if ($row_grandchild)     {

      $newmainid = $row_grandchild["branch_number"];

    }

    if ($oldmainid != $newmainid)     {

      $n++;

    }

  }



  echo "var grandchild_WAJA = WAJA;\n";

  echo "WAJA = null;\n";

  echo "</SC" . "RIPT>\n";

}

?>

<?php

if ($row_child)     {

  echo "<SC" . "RIPT>\n";

  echo "var WAJA = new Array();\n";



  $oldmainid = 0;

  $newmainid = $row_child["branch_number"];

  if ($oldmainid == $newmainid)    {

    $oldmainid = "";

  }

  $n = 0;

  while ($row_child)     {

    if ($oldmainid != $newmainid)     {

      echo "WAJA[".$n."] = new Array();\n";

      echo "WAJA[".$n."][0] = '".WA_DD_Replace($newmainid)."';\n";

      $m = 1;

    }



    echo "WAJA[".$n."][".$m."] = new Array();\n";

    echo "WAJA[".$n."][".$m."][0] = "."'".WA_DD_Replace($row_child["branch_number"])."'".";\n";

    //echo "WAJA[".$n."][".$m."][1] = "."'".WA_DD_Replace($row_child["surgery_date"])."'".";\n";



	

	echo "WAJA[".$n."][".$m."][1] = "."'".WA_DD_Replace(date('D, dS M Y', strtotime($row_child["surgery_date"])))."'".";\n";  





    $m++;

    if ($oldmainid == 0)      {

      $oldmainid = $newmainid;

    }

    $oldmainid = $newmainid;

    $row_child = mysql_fetch_assoc($child);

    if ($row_child)     {

      $newmainid = $row_child["branch_number"];

    }

    if ($oldmainid != $newmainid)     {

      $n++;

    }

  }



  echo "var child_WAJA = WAJA;\n";

  echo "WAJA = null;\n";

  echo "</SC" . "RIPT>\n";

}

function WA_DD_Replace($startStr)  {

  $startStr = str_replace("'", "|WA|", $startStr);

  $startStr = str_replace("\\", "\\\\", $startStr);

  $startStr = preg_replace("/[\r\n]{1,}/", " ", $startStr);

  return $startStr;

}

?>

<link href="style.css" rel="stylesheet" type="text/css" />

<style type="text/css">

<!--

#drugs {

	position:absolute;

	left:362px;

	top:381px;

	width:700px;

	height:300px;

	z-index:1;

	visibility: visible;

}

#calendar {

	position:absolute;

	left:342px;

	top:345px;

	width:711px;

	height:297px;

	z-index:2;

}

#calendar {

	position:absolute;

	left:342px;

	top:390px;

	width:700px;

	height:300px;

	z-index:2;

	overflow: hidden;

	visibility: visible;

}

#leftdiv {

	position:absolute;

	left:892px;

	top:2px;

	width:174px;

	height:587px;

	z-index:0;

	font-family: Arial, Helvetica, sans-serif;

}

#rightdiv {

	position:absolute;

	left:1px;

	top:-2px;

	width:179px;

	height:591px;

	z-index:0;

}

#apDiv2 {

	position:absolute;

	left:193px;

	top:318px;

	width:690px;

	height:9px;

	z-index:5;

}

#apDiv3 {

	position:absolute;

	left:198px;

	top:278px;

	width:249px;

	height:14px;

	z-index:5;

}

#apDiv1 {

	position:absolute;

	width:200px;

	height:115px;

	z-index:3;

}

#apDiv4c {

	position:absolute;

	width:700px;

	height:221px;

	z-index:1;

	visibility: visible;

}

#apDiv5d {

	position:absolute;

	width:702px;

	height:220px;

	z-index:1;

	top: 312px;

	visibility: visible;

}

h2 {

	font-size: 0.9cm;

	color: #000;

}



.BlackBorder {

border: 1px solid #000000;

}

h4 {

	font-size: 10pt;

}

a:link {

	text-decoration: none;

	color: #000;

}

a:visited {

	text-decoration: none;

}

a:hover {

	text-decoration: underline;

	color: #009;

}

a:active {

	text-decoration: none;

}

h6 {

	font-size: 10pt;

	color: #999;

}

table#menubar a:link {

	color: #000;

}

table#menubar a:visited {

	color: #000;

}

table#menubar a:hover {

	color: #009;

}

table#menubar a:active {

	text-decoration: underline;

}

h4 {

	font-size: 11pt;

	margin-left: 0px;

}

body {

body,td,th {

	font-size: 10pt;

}

body,td,th {

	font-size: 11pt;

	padding-left: 3px;

	color: #000;

}

-->

</style>

<script type="text/javascript">

<!--

function WA_ClientSideReplace(theval,findvar,repvar)     {

  var retval = "";

  while (theval.indexOf(findvar) >= 0)    {

    retval += theval.substring(0,theval.indexOf(findvar));

    retval += repvar;

    theval = theval.substring(theval.indexOf(findvar) + String(findvar).length);

  }

  retval += theval;

  if (retval == "" && theval.indexOf(findvar) < 0)    {

    retval = theval;

  }

  return retval;

}



function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}



function WA_UnloadList(thelist,leavevals,bottomnum)    {

  while (thelist.options.length > leavevals+bottomnum)     {

    if (thelist.options[leavevals])     {

      thelist.options[leavevals] = null;

    }

  }

  return leavevals;

}



function WA_FilterAndPopulateSubList(thearray,sourceselect,targetselect,leaveval,bottomleave,usesource,delimiter)     {

  if (bottomleave > 0)     {

    leaveArray = new Array(bottomleave);

    if (targetselect.options.length >= bottomleave)     {

      for (var m=0; m<bottomleave; m++)     {

        leavetext = targetselect.options[(targetselect.options.length - bottomleave + m)].text;

        leavevalue  = targetselect.options[(targetselect.options.length - bottomleave + m)].value;

        leaveArray[m] = new Array(leavevalue,leavetext);

      }

    }

    else     {

      for (var m=0; m<bottomleave; m++)     {

        leavetext = "";

        leavevalue  = "";

        leaveArray[m] = new Array(leavevalue,leavetext);

      }

    }

  }  

  startid = WA_UnloadList(targetselect,leaveval,0);

  mainids = new Array();

  if (usesource)    maintext = new Array();

  for (var j=0; j<sourceselect.options.length; j++)     {

    if (sourceselect.options[j].selected)     {

      mainids[mainids.length] = sourceselect.options[j].value;

      if (usesource)     maintext[maintext.length] = sourceselect.options[j].text + delimiter;

    }

  }

  for (var i=0; i<thearray.length; i++)     {

    goodid = false;

    for (var h=0; h<mainids.length; h++)     {

      if (thearray[i][0] == mainids[h])     {

        goodid = true;

        break;

      }

    }

    if (goodid)     {

      theBox = targetselect;

      theLength = parseInt(theBox.options.length);

      theServices = thearray[i].length + startid;

      var l=1;

      for (var k=startid; k<theServices; k++)     {

        if (l == thearray[i].length)     break;

        theBox.options[k] = new Option();

        theBox.options[k].value = thearray[i][l][0];

        if (usesource)     theBox.options[k].text = maintext[h] + WA_ClientSideReplace(thearray[i][l][1],"|WA|","'");

        else               theBox.options[k].text = WA_ClientSideReplace(thearray[i][l][1],"|WA|","'");

        l++;

      }

      startid = k;

    }

  }

  if (bottomleave > 0)     {

    for (var n=0; n<leaveArray.length; n++)     {

      targetselect.options[startid+n] = new Option();

      targetselect.options[startid+n].value = leaveArray[n][0];

      targetselect.options[startid+n].text  = leaveArray[n][1];

    }

  }

  for (var l=0; l < targetselect.options.length; l++)    {

    targetselect.options[l].selected = false;

  }

  if (targetselect.options.length > 0)     {

    targetselect.options[0].selected = true;

  }

}

//-->

</script>

</head>



<body>

<table width="800" border="0" id="table3">

  <tr>

    <th width="389" align="left" scope="col"><h2>Vet Surgery<br />

    Connect</h2></th>

    <th width="12" scope="col">&nbsp;</th>

    <th width="385" align="right" scope="col"><p><?php echo $row_Recordset5['practice_name']; ?></p></th>

  </tr>

  <tr>

    <td colspan="3"><table width="100%" border="0">

      <tr>

        <td width="74%" nowrap="nowrap" scope="col">&nbsp;</td>

        <th width="14%" rowspan="3" align="right" nowrap="nowrap" scope="col"><a class="menu" href="main.php">Client Summary</a></th>

        <td width="5%" align="right" nowrap="nowrap" scope="col">&nbsp;</td>

        <th width="7%" rowspan="3" align="right" nowrap="nowrap" scope="col"><p><a class="menu" href="<?php echo $logoutAction ?>">Logout</a></p></th>

      </tr>

      <tr>

        <td nowrap="nowrap" scope="col"><hr /></td>

        <td width="5%" align="right" nowrap="nowrap" scope="col"><hr /></td>

      </tr>

      <tr>

        <td height="24" nowrap="nowrap" scope="col">&nbsp;</td>

        <td width="5%" align="right" nowrap="nowrap" scope="col">&nbsp;</td>

      </tr>

    </table></td>

  </tr>

  <tr>

    <td valign="top"><table width="100%" border="0" id="table2">

      <tr>

        <td width="100%" align="left" scope="col"><h4>Appointment Request Form</h4></td>

      </tr>

      <tr>

        <td align="left" scope="col">&nbsp;

                

        </td>

      </tr>

      <tr>

        <td align="left" valign="top" scope="col">&nbsp;</td>

      </tr>

      <tr>

        <td scope="col">

        

                <form action="contact.php" method="post" id="form1" name="form1">

          <table width="100%" border="0" id="table1">

            <tr>

              <th width="100%" align="left" scope="col"><input name="clientid" type="hidden" id="clientid" value="<?php echo $row_Recordset1['client_pms_id']; ?>" />

                <input name="animalid" type="hidden" id="animalid" value="<?php echo $row_Recordset4['animal_pms_id']; ?>" />

                <input name="subject" type="hidden" id="subject" value="VSC Appointment" /></th>

            </tr>

            <tr>

              <td align="left" scope="col">&nbsp;</td>

            </tr>

            <tr>

    <td align="left" scope="col"><p>1. Surgery:

        <select name="parent" size="1" id="parent" onchange="WA_FilterAndPopulateSubList(child_WAJA,MM_findObj('parent'),MM_findObj('child'),1,0,false,': ')">

          <option value="">Please Select Surgery</option>

          <?php

do {  

?>

          <option value="<?php echo $row_parent['branch_number']?>"><?php echo $row_parent['branch_name']?></option>

          <?php

} while ($row_parent = mysql_fetch_assoc($parent));

  $rows = mysql_num_rows($parent);

  if($rows > 0) {

      mysql_data_seek($parent, 0);

	  $row_parent = mysql_fetch_assoc($parent);

  }

?>

        </select>

    </p></td>

  </tr>

            <tr>

              <th align="left" scope="col">&nbsp;</th>

            </tr>

            <tr>

              <td align="left" scope="col"><p>2. Date: 

                

                <select name="child" size="1" id="child" onchange="WA_FilterAndPopulateSubList(grandchild_WAJA,MM_findObj('child'),MM_findObj('grandchild'),1,0,false,': '); showUser(this.value)">

              

                  <option value="">Please Select Date</option>

                  

                </select>

              </p></td>

            </tr>

            <tr>

              <th>&nbsp;</th>

            </tr>

            <tr>

    <td align="left" scope="col"><p>3. Select vet:

        <select name="grandchild" size="1" id="grandchild">

          <option value="Any">Any</option>

          <option value="Test">Test</option>

        </select>

    </p></td>

  </tr>

            <tr>

              <th align="left" scope="col">&nbsp;</th>

            </tr>

            <tr>

    <td align="left" scope="col"><p>4. Preferred appointment time:</p></td>

  </tr>

  <tr>

    <td align="left" scope="col"><p>Between</p>

      <p>

  <select name="time1" id="time1">

    <option value="">Please select time</option>

    <option>08:00</option>

    <option>09:00</option>

    <option>10:00</option>

    <option>11:00</option>

    <option>12:00</option>

    <option>13:00</option>

    <option>14:00</option>

    <option>15:00</option>

    <option>16:00</option>

    <option>17:00</option>

    <option>18:00</option>

  </select> 

      </p>

      <p>and</p>

      <p>

  <select name="time2" id="time2">

    <option value="">Please select time</option>

    <option>08:00</option>

    <option>09:00</option>

    <option>10:00</option>

    <option>11:00</option>

    <option>12:00</option>

    <option>13:00</option>

    <option>14:00</option>

    <option>15:00</option>

    <option>16:00</option>

    <option>17:00</option>

    <option>18:00</option>

  </select>

      </p></td>

  </tr>

  <tr>

    <th align="left" scope="col">&nbsp;</th>

  </tr>

  <tr>

    <td align="left" scope="col"><p>5. Select a Reason: 

      

        <select name="reason" id="reason">

          <option value="">Please select a reason</option>

          <option>First Vaccination</option>

          <option>Booster Vaccination</option>

          <option>General Checkup</option>

          <option>Ear Problems</option>

          <option>Eye Problems</option>

          <option>Lame</option>

          <option>Fleas</option>

          <option>Vomiting</option>

          <option>Other</option>

        </select>

    </p></td>

  </tr>

  <tr>

    <th align="left" scope="col">&nbsp;</th>

  </tr>

  <tr>

    <td align="left" scope="col"><p>6. Optional: Send a message to your Vet</p></td>

  </tr>

  <tr>

    <th align="left" scope="col"><textarea name="comments" id="comments" cols="75" rows="3" style="width:300px; height:85px;"></textarea></th>

  </tr>

  <tr>

    <th align="left" scope="col">&nbsp;</th>

  </tr>

  <tr>

    <td align="left" scope="col"><p>7. Send your appointment request</p></td>

  </tr>

  <tr>

    <th align="left" scope="col">&nbsp;</th>

  </tr>

  <tr>

    <th align="left" scope="col"><input name="send" type="submit" id="send" value="Send" /></th>

  </tr>

</table>

<p></p>

          </form>



</p></td>

      </tr>

    </table></td>

    <td>&nbsp;</td>

    <td valign="top"><table width="100%" border="0"><?php do { ?><?php } while ($row_Recordset3 = mysql_fetch_assoc($Recordset3)); ?>

        <tr>

          <td width="16%" align="left" scope="col"><h4>Owner: </h4></td>

          <td width="45%" align="left" nowrap="nowrap" scope="col"><p><?php echo $row_Recordset1['client_title']; ?> <?php echo $row_Recordset1['client_initials']; ?> <?php echo $row_Recordset1['client_name']; ?></p></td>

        </tr>

        <tr>

          <td align="left" scope="col"><h4>Pet: </h4></td>

          <td align="left" scope="col"><p><?php echo $row_Recordset4['animal_name']; ?></p></td>

        </tr>

        <tr>

          <td colspan="2" align="left" scope="col">&nbsp;</td>

        </tr>

        <tr>

          <td colspan="2" align="center" class="BlackBorder" scope="col"><table width="90%" border="0">

            <tr>

              <th width="50%" align="center" scope="col"><h4>Surgery Times</h4></th>

              <th width="50%" align="center" scope="col"><h4>Availability</h4></th>

            </tr>

            <tr>

              <td align="center"><p>9:00 - 11:00</p></td>

              <td align="center"><span style="font-weight: bold; color: #090;">Good</span></td>

            </tr>

            <tr>

              <td align="center"><p>11:00 - 13:00</p></td>

              <td align="center"><span style="font-weight: bold; color: #00C;">Fair</span></td>

            </tr>

            <tr>

              <td align="center"><p>13:00 - 15:00</p></td>

              <td align="center"><span style="font-weight: bold; color: #F90;">Busy</span></td>

            </tr>

            <tr>

              <td align="center"><p>15:00 - 17:00</p></td>

              <td align="center"><span style="font-weight: bold; color: #F00;">Full</span></td>

            </tr>

          </table></td>

        </tr>

        <tr>

          <td colspan="2" align="left" scope="col">&nbsp;</td>

        </tr>

        <tr>

<td colspan="2" align="left" scope="col"><div id="txtHint"><b> Availability info will be listed here.</b></div>





</td>

        </tr>

        <tr>

<td colspan="2" align="left" scope="col">&nbsp;</td>

        </tr>

        <tr>

          <td colspan="2" align="left" scope="col">&nbsp;</td>

        </tr>

        <tr>

<td colspan="2" align="left" scope="col">&nbsp;</td>

        </tr>

        <tr>

          <td colspan="2" align="left" scope="col">&nbsp;</td>

        </tr>

        <tr>

          <td colspan="2" align="left" scope="col">&nbsp;</td>

        </tr>

    </table></td>

  </tr>

  <tr>

    <td colspan="3" nowrap="nowrap">&nbsp;</td>

  </tr>

  <tr>

    <td colspan="3" nowrap="nowrap"><hr /></td>

  </tr>

  <tr>

    <td colspan="3" nowrap="nowrap"><h5><span style="color: #999;">The name Vet Surgery Connect and the logo are trademarks of InterNetPet Ltd. Copyright 2010 InterNetPet Ltd. All rights reserved.</span></h5></td>

  </tr>

</table>

<blockquote>&nbsp;</blockquote>

</body>

</html>

<?php

mysql_free_result($Recordset1);



mysql_free_result($Recordset2);



mysql_free_result($Recordset3);



mysql_free_result($Recordset4);



mysql_free_result($Recordset5);



mysql_free_result($Recordset6);



mysql_free_result($Recordset7);



mysql_free_result($parent);



mysql_free_result($child);



mysql_free_result($grandchild);



?>

Open in new window

0
Comment
Question by:alexking
  • 8
  • 7
15 Comments
 

Author Comment

by:alexking
ID: 33489338
Here is the getuser.php as described at the w3 link above.


<?php

$q=$_GET["q"];



$con = mysql_connect('***', '***', '***');



if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }



mysql_select_db("vsconnect", $con);



$sql="SELECT * FROM surgery_table WHERE surgery_1_date = '".$q."'";



$result = mysql_query($sql);



echo "<table border='1'>

<tr>

<th>SurgeryStart</th>

<th>SurgeryEnd</th>

<th>Availability</th>

</tr>";



while($row = mysql_fetch_array($result))

  {

  echo "<tr>";

  echo "<td>" . $row['surgey_1_start'] . "</td>";

  echo "<td>" . $row['surgery_1_end'] . "</td>";

  echo "<td>" . $row['surgery_1_busy_string'] . "</td>";

  echo "</tr>";

  }

echo "</table>";



mysql_close($con);



?>

Open in new window

0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 33489535
Hi alexking,

It looks like you are mixing and matching javascript solutions?  Line 695:

<select name="child" size="1" id="child" onchange="WA_FilterAndPopulateSubList(grandchild_WAJA,MM_findObj('child'),MM_findObj('grandchild'),1,0,false,': '); showUser(this.value)">

So if you are not using WebAssist to accomplish the goal, remove the:

onchange="WA_FilterAndPopulateSubList(grandchild_WAJA,MM_findObj('child'),MM_findObj('grandchild'),1,0,false,': ');

Also, look at your page with Firefox and Firebug to see if any javascript errors pop up.
0
 

Author Comment

by:alexking
ID: 33489637
Hi jason1178,

Yes I am mixing javascript solutions. I am using Webassist to populate the three drop downs and on top of that I would like a dynamic information box to pop up on the side of the second drop down with information in it.

The Webassist dropdowns work fine and the 'information box' does appear with the headers defined in getuser.php but no information is pulled from the database. Any idea why that would be?

I have been testing in Safari up to now and I tried in Firefox as you suggested but the drop downs do not even work!!! So many questions! I will try and work that one out and install firebug also so thanks for the tip.

Thanks
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 33490307
>> Any idea why that would be?

Hard to say without being able to get on the page and play with it while using a debugger.  At this point it could be a javascript or a PHP problem...
0
 

Author Comment

by:alexking
ID: 33526931
Hi,

I am not getting any PHP errors but do not know how to debug Javascript, can you recommend some resources? I am using Dreamweaver CS4 and tend to test with Safari and Firefox initially. I have tried tinkering with Safari Javascript Debugging and Profiling but no errors come up.

I am guessing I need something that lets me step through the code. This is the last piece of functionality the page needs! Thanks.
0
 

Author Comment

by:alexking
ID: 33537051
Hi,

I am looking to troubleshoot this as quickly as I can (over the next few days), please let me know if I should seek help elsewhere or repost in a different section.

Thank you, much appreciated.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 33537615
If you want to do it yourself, you would need to deal with your php and javascript and figure out where your logic is going wrong.  

If you want help, posting a live link along with the complete source codes so WE can go through it and see where things don't work is your only option.  Merely not getting a PHP error does not mean your PHP logic is correct and things are firing the way they are supposed to.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:alexking
ID: 33547595
Hi Jason,

The code is question is at:

www.vetsurgeryconnect.com

temp login: gh4 5bf
password: 62a6

This is all dummy data at the moment as the site is not live but still in test phase.

After Login, click on 'Jenny' under Pets then 'RequestAppointment' at the top - this takes you to the form with the right Session and URL variables active.

The first three drop downs (Surgery, Date and Vet) are using Webassist Dynamic Drop Downs for functionality. OnChange of the date drop down I also want a box to show availability on the right of the screen. I have done a mock up of the box but the functionality is currently tied to the txthint div where it says 'Availability will be listed here'.

onChange of the date drop down you will see the header change as specified in the getuser.php file but no data from the database.

The code for these two pages is above.

Any suggestions at this stage will be appreciated.

Thank you.
0
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 500 total points
ID: 33547940
Ok.

When I look at the generated source, I see:

22010-02-24

as the values in "child".  Are you sure that date has a matching value in surgery_table.surgery_1_date ?
0
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 500 total points
ID: 33548038
Ok, did a little more testing.

I simplified the code as much as possible to test the AJAX call to make sure that is not the problem.  Good news...it isn't.  So I really do think it may be as simple as the query not finding any records and the structure of the code was correct all along.

Here are my testing files:
untitled.php
getuser.php
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 33548044
Results from the above (ignore the PHP error...that was my bad)


Test.png
0
 

Author Comment

by:alexking
ID: 33549119
The date in the database is 2010-02-24. The generated source you show has an extra '2' on the front of it which obviously does not match the database record.

Any ideas where this '2' comes from? Could it be something Webassist Dynamic dropdowns uses or an issue with the way I am displaying the date in the dropdown?

Thanks for pinpointing the issue so quickly.
0
 

Author Comment

by:alexking
ID: 33549221
On the recordset for child (the date drop down), I have used a concatenation of branch number and date (I do not understand this fully but it achieved what I needed). I am guessing that the 22010-02-24 that you found refers to branch 2 and date 2010-02-24.

How can I get the AJAX query to ignore this concatenation and just look at the date element?

 
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 33551732
In getuser.php:

<?php
$qq=$_GET["q"];

$q = substr($qq, 1, 10); // should return everything after the initial character thus giving you a real date

0
 

Author Closing Comment

by:alexking
ID: 33554805
Thank you very much. Helped me see where I was going wrong and how I could fix it. Such speedy response time as well!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now