I am just beginning to get the idea on how to put together the above four source codes to produce, in this case, a Contact Database/Display program.
On a 0-10 learning scale I feel like a 3.
My current problem is:

ContactRevise3.html calls revise.php with the following script:

<script type="text/javascript" >
		$.post("revise.php", {id: revId, revData: revFlg, dName: dispName}, showResultsFromServer, "json");
//  ==================  showResults From Server  =====================	
			function showResultsFromServer(data) {	
				var content="<table border='3' cellpadding='5' bgcolor='#feede3' class='rTbl'>"
				+"<caption class='rTbl' ><big><b>Data currently stored in the database.</b></big></caption>\n"
				+ "<tbody><tr class='rTbl'><th class='rTbl'>Field</th><th class='rTbl'>Value</th></tr>\n";
				$.each(data, function(key, value) {
					if(key==="Name_ID") { return true; };
					content+= "<tr class='rTbl'><td class='rTbl'>" + key + "</td><td class='rTbl'>" + value + "</td></tr>\n"

				}); // $.each
				content+= "</tbody></table>";
				content+="<div class='controls'>";
				content+="<button type='button' name='revise' class='hov'"  
				+"onclick=\"window.location.href='ContactFrontEnd.php'\"> Go Back</button></div>\n"			
			}; // showResults			 

The result is a page showing the header only. It is supposed to also show a table/form allowing
the revision of fields to be stored in the database. The array shown in form_output.png is returned from revise.php. When my current problem is solved that array will be returned to ContactRevise3.html as JSON
(json_encode($rowssaved) to be displayed by showResultsByServer() as above.

If I call revise.php by itself it works as intended. See form_output.png. If it is called as above all I get, looking at firebug output, is the generated source code. See generatedSource.png.

I am beginning to think, as there are no errors generated, that I have to append all this generated code to a <div> somehow.

If this is correct I'd like some advice on how to do it. Otherwise ???

Thanks in advance, RP.

5 Years
Discussion Span
Last Post by vaultdweller123

My query didn't upload the .png files!

GUESS WHAT?? My fault.

Attachments form_output.png 118.67 KB generatedSource.png 163.89 KB

Thanks for your quick reply.

Sorry I didn't explain the problem very well.

A typical session is.

1. Select a contact person from MYSql database.
2. Decide to change/add data in/to the record.
3. Call ContactRevise.html which in turn calls revise.php with $.post...
a. Revise.php generates a table/form showing all fields in that record
regardless of containing data or not.
b. Change or add data in the table/form and submit.
c. UPDATE the database and create an array of fields in the record that contain data only.
No blank fields.
d. Encode the array to JSON format.
e. RETURN the JSON data to ContactRevise.html to be displayed with
the callback function, showResultsFromServer(data).
4. ShowResultsFromServer(data) creates a table showing the UPDATED record data for the contact in <div id="#rbox">.

PROBLEM: In 3a. the table/form is NOT DISPLAYED. If I set up a test id to query the database
and run revise.php as a stand alone program the table/form displays fine and everything works.

revise.php WILL NOT WORK WHEN CAllED FROM ContactRevise.php.

What I've shown you is only what revise.php does now. It is intended to go as
far as displaying the array only.

Hope this adequately describes my problem now.

Thanks again, RP


Thanks vaultdweller, I'll upgrade myself to a 4.

I think that maybe the problem is this. The table/form I want to implement is really a mid-stage event. I am asking revise.php to produce this form. The user changes the data shown on the form, the data is updated by MySql, the database is again queried for the current data AND THEN the array is encoded and sent to the call back function in the preceding program. Revise.php is not showing the table/form to update. There is no problem with the array revise.php produces and subsequent code re: the call back. The question becomes WHY WON'T revise.php DISPLAY THE FORM TO CHANGE?

Don't forget, revise.php, on a standalone basis works very well.

(I'm giving myself a 2 on explaining myself.)


Here are the modules.

                 "-//W3C//DTD HTML 4.01 Transitional//EN"

<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" >
<title> Revise Contact </title>

<!--link rel="stylesheet " type="text/css" href="../css/frontend.css" /-->
<link rel="stylesheet " type="text/css" href="../css/load.css" />
<link rel="stylesheet " type="text/css" href="../css/connect.css" />

<script type="text/javascript" src="../jquery/jquery-1.7.js"></script> 

<script type="text/javascript" src=" ../jquery/common.js"></script>  

<script type="text/javascript" >

	var revId = unescape($.getUrlVar('id'));           // see common.js
	var dispName =unescape($.getUrlVar('dname'));
	var revFlg= unescape($.getUrlVar('revFlg'));
    var hashes = $.trim(unescape(window.location.href.slice(window.location.href.indexOf('?') + 1).split('&')));


<!-- ========== header  ================ -->

	<div id="header">
  		<h1><img src="../images/AmericanFlag2.png" alt="Company logo" height="90px" />
				Rick and Polly&rsquo;s Contacts</h1>
   		<h3> <span style="padding-left: 140px">Revise Contact Information for</span>
   		<span style="color:red;"><script> type="text/javascript"> document.write(" " +dispName );</script></span></h3>
<script type="text/javascript" >
		$.post("revise.php", {id: revId, revData: revFlg, dName: dispName}, showResultsFromServer, "json"); // revise data
//  ==================  showResults From Server  =====================	
			function showResultsFromServer(data) {	
				var content="<table border='3' cellpadding='5' bgcolor='#feede3' class='rTbl'>"
				+"<caption class='rTbl' ><big><b>Data currently stored in the database.</b></big></caption>\n"
				+ "<tbody><tr class='rTbl'><th class='rTbl'>Field</th><th class='rTbl'>Value</th></tr>\n";
				$.each(data, function(key, value) {
					if(key==="Name_ID") { return true; };
					content+= "<tr class='rTbl'><td class='rTbl'>" + key + "</td><td class='rTbl'>" + value + "</td></tr>\n"

				}); // each
				content+= "</tbody></table>";
				content+="<div class='controls'>";
				content+="<button type='button' name='revise' class='hov'"  
				+"onclick=\"window.location.href='ContactFrontEnd.php'\"> Go Back</button></div>\n"
				content+="<button type='button' name='save' class='hov'"  
				+"onclick=\"window.location.href='contactSavRev.php'\"> Save Data</button></div>\n"				
			}; // showResults

 	<div id="rbox">
 	<div id="rbox2">

<?php session_start(); 

set_include_path( '../include' );
error_reporting (E_ALL ^ E_NOTICE);

require_once "functions.inc";
require_once "functions-contacts.inc";

   $hostName = "localhost";
   $databaseName = "contacts";
   $username = "rick";
   $password = "rick";

  if(empty($revId)) {

//echo " Id passed  " . $revId;  
  $revId='1172'; // for testing
   	$cxn = @ mysqli_connect($hostName, $username, $password, $databaseName); //Connect to the MySQL server
     if (mysqli_connect_errno()) {
    		printf("Connect failed: %s\n", mysqli_connect_error());
	$query=sprintf("SELECT * FROM %s WHERE Name_Id=%s;", $table, $revId);	// show current contents of record
		$result = mysqli_query($cxn, $query) or exit( mysqli_error( $cxn ));
		while($row = mysqli_fetch_assoc($result)) {

foreach($rowsRead[0] as $key => $value) {
	if($value!="") $connectData[$key]=$value;

printf("<div id='who'>");

printf("<fieldset class='rev1'>");
printf("<legend>Revising Record %s </legend>", $revId);
printf("<form name='revContactForm' id='revContactForm' method='POST' action=''>\n");
printf("<table class='revForm' border='3' cellpadding='5'  bgcolor='#feede3' ><tr>\n");

printf("<td><input type='text' hidden='hidden' name='revFlg' id='revFlg' value='true'></input></td></tr>\n");
printf("<td><input type='text' hidden='hidden' name='revId' id='revId' value=%s></input></td></tr>\n",$revId);

foreach($rowsRead[0] as $key => $value) {

	if($key=='Name_ID' | $key=='Vendor_ID') {
		printf("<td><label for='%s'>%s</label></td>\n",strtolower($key), preg_replace("/_/"," ",$key));
		if($key=="Display_Name") {
    		printf('<td><input type="text" name="%s" onfocus="showDisplayName();" id="%s" value="%s"></input></td></tr>\n',
    		strtolower($key), strtolower($key), $value);		

		if (contains($key, "Notes")) {
			printf("<td><textarea name='%s' id='%s'  rows=5 cols=81> '%s' </textarea></td></tr>\n",strtolower($key),
			 strtolower($key), $value);
		printf("<td><input type='text' name='%s' id='%s' value='%s'></input></td></tr>\n", strtolower($key), strtolower($key), $value);
	}; // for each	

printf("<tr><td><input type='submit' class='hov'  name='submit' value='Save Contact Data'></input></td></tr>\n");	

printf("<div id='inputForm'></div>\n");  // <!-- inputForm -->\n");
 printf("<div id='controls'>\n");
	 //printf("<button type='button' class='hov' name='connect' onclick=window.location.href='ContactFrontEnd.php'>Go Back</button>\n");            
 	//printf("<button type='button' class='hov'  name='savContact' value='Save Contact Data' onclick=saveContact()>Save Contact</button>\n");
  	//printf("<input type='submit' class='hov'  name='submit' id='submit' value='Save Contact Data'></input>\n");	
printf("<div id='rbox'>\n</div>\n");		
printf("<div id='rbox2'>\n</div>\n");

// listArray($_POST); 

if (isset($_POST['submit'])) {
	foreach($_POST as $key => $value) {
		if($value!="") $savedData[$key]=$value;
	} // post
	$query2="UPDATE " . $table . " SET "; // update database
	foreach($savedData as $key => $value) {
		$query2 .= $key ."='" . mysqli_real_escape_string($cxn, $value) . "', "; // mysqli_real_escape_string(
	} // save

	$query2=rtrim($query2, ", "); // get rid of last comma

	$query2 .=" WHERE Name_ID= '" . $revId . "';";

	$result = mysqli_query($cxn, $query2) or exit( mysqli_error( $cxn ));	// Update database
} // isset post

	$query3=sprintf("SELECT * FROM %s WHERE Name_Id=%s;", $table, $revId);	
		$result = mysqli_query($cxn, $query3) or exit( mysqli_error( $cxn )); // Read back data just Updated
		while($row = mysqli_fetch_assoc($result)) {
foreach($rowsUpdated[0] as $key => $value) {  // Trim out fields with no data
	if($value=="") {
	}else {
listArray($rowsSaved); // testing -- return Updated data, php_encode later	
//echo json_encode($rowsSaved);	


hey dude, i assume you know how to use firebug, try to check firebug's NET tab, and then check your request there, then click on the response tab, to see the response, because you could've error on your revise.php


ok try changing this

$.post("revise.php", {id: revId, revData: revFlg, dName: dispName}, showResultsFromServer, "json");


$.post("revise.php", {id: revId, revData: revFlg, dName: dispName}, showResultsFromServer);

ok ill be back ill just have my lunch


I can barely get around in Firebug. The generated source came from the results thing.

Here is the database I am using.

Don't forget I'm only interested in revise.php showing a table/form at this time. What Firebug shows is the generated code to produce the table/form.

-- phpMyAdmin SQL Dump
-- version 3.3.2deb1
-- http://www.phpmyadmin.net
-- Host: localhost
-- Generation Time: Dec 02, 2011 at 03:59 PM
-- Server version: 5.1.41
-- PHP Version: 5.3.2-1ubuntu4.10


/*!40101 SET NAMES utf8 */;

-- Database: `contacts`
-- drop database if exists contacts;
-- create database contacts;
-- use contacts;
-- --------------------------------------------------------

-- Table structure for table `cdata`

  `First_Name` varchar(50) DEFAULT NULL,
  `Last_Name` varchar(50) DEFAULT NULL,
  `Display_Name` varchar(75) NOT NULL DEFAULT 'TempData',
  `Home_Phone` varchar(14) DEFAULT NULL,
  `Home_Cell` varchar(14) DEFAULT NULL,
  `Home_Email` varchar(45) DEFAULT NULL,
  `Home_Address` varchar(60) DEFAULT NULL,
  `Home_City` varchar(30) DEFAULT NULL,
  `Home_State` varchar(5) DEFAULT NULL,
  `Home_Zip` varchar(12) DEFAULT NULL,
  `Job_Title` varchar(45) DEFAULT NULL,
  `Department` varchar(30) DEFAULT NULL,
  `Vendor_ID` int(11) DEFAULT NULL,
  `Organization` varchar(45) DEFAULT NULL,
  `Work_Address` varchar(61) DEFAULT NULL,
  `Work_City` varchar(19) DEFAULT NULL,
  `Work_State` varchar(5) DEFAULT NULL,
  `Work_Zip` varchar(12) DEFAULT NULL,
  `Work_Phone` varchar(14) DEFAULT NULL,
  `Work_Fax` varchar(14) DEFAULT NULL,
  `Work_Email` varchar(45) DEFAULT NULL,
  `Website` varchar(40) DEFAULT NULL,
  `Home_Notes` varchar(400) DEFAULT NULL,
  `Work_Notes` varchar(400) DEFAULT NULL,
  PRIMARY KEY (`Name_ID`),
  UNIQUE KEY `Display_Name` (`Display_Name`)

-- Dumping data for table `cdata`

INSERT INTO `cdata` (`Name_ID`, `First_Name`, `Last_Name`, `Display_Name`, `Home_Phone`, `Home_Cell`, `Home_Email`, `Home_Address`, `Home_City`, `Home_State`, `Home_Zip`, `Job_Title`, `Department`, `Vendor_ID`, `Organization`, `Work_Address`, `Work_City`, `Work_State`, `Work_Zip`, `Work_Phone`, `Work_Fax`, `Work_Email`, `Website`, `Home_Notes`, `Work_Notes`) VALUES
(1, 'Warren', 'Aaberg', 'Aaberg, Warren', '', '', 'WMTTAA@charter.net', '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', ''),
(3, 'Elizabeth', 'Ahlgren', 'Ahlgren, Elizabeth', '', '', 'liznron@hotmail.com', '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', ''),
(4, 'Irma', 'Aldinger', 'Aldinger, Irma', '255.353.5555', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
(5, 'Cathie', 'Allen', 'Allen, Cathie', '', '', 'cathieallen19@hotmail.com', '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', ''),

firebug-response-body.txt is copied from Firebug.

That last array it shows is exactly what it should be before JSON encoding. All that above is supposed to generate the table/form inside revise.php so you can change the data on the fly. Looking at NET shows no errors.

Getting late here.Talk later.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


    <title>Functions for Contacts</title>
<style type="text/css">

table input {
	color: blue;




<script type='text/javascript' >
function showDisplayName() {
var first = document.getElementById('first_name');
var second = document.getElementById('last_name');
var third = document.getElementById('display_name');
third.value=second.value+', '+first.value;
<div id='who'><fieldset class='rev1'><legend>Revising Record 1172 </legend><form name='revContactForm' id='revContactForm' method='POST' action=''>
<table class='revForm' border='3' cellpadding='5'  bgcolor='#feede3' ><tr>
<td><input type='text' hidden='hidden' name='revFlg' id='revFlg' value='true'></input></td></tr>
<td><input type='text' hidden='hidden' name='revId' id='revId' value=1172></input></td></tr>
<td><label for='first_name'>First Name</label></td>
<td><input type='text' name='first_name' id='first_name' value='Alfred H.'></input></td></tr>
<td><label for='last_name'>Last Name</label></td>
<td><input type='text' name='last_name' id='last_name' value='Google707'></input></td></tr>
<td><label for='display_name'>Display Name</label></td>
<td><input type="text" name="display_name" onfocus="showDisplayName();" id="display_name" value="Google707, Alfred H."></input></td></tr>\n<td><label for='home_phone'>Home Phone</label></td>
<td><input type='text' name='home_phone' id='home_phone' value='208.123.5555'></input></td></tr>
<td><label for='home_cell'>Home Cell</label></td>
<td><input type='text' name='home_cell' id='home_cell' value='509.123.5555'></input></td></tr>
<td><label for='home_email'>Home Email</label></td>
<td><input type='text' name='home_email' id='home_email' value='alfredh@net.com'></input></td></tr>
<td><label for='home_address'>Home Address</label></td>
<td><input type='text' name='home_address' id='home_address' value='1234 MyRoad'></input></td></tr>
<td><label for='home_city'>Home City</label></td>
<td><input type='text' name='home_city' id='home_city' value='Pigeon'></input></td></tr>
<td><label for='home_state'>Home State</label></td>
<td><input type='text' name='home_state' id='home_state' value='CO'></input></td></tr>
<td><label for='home_zip'>Home Zip</label></td>
<td><input type='text' name='home_zip' id='home_zip' value='23456'></input></td></tr>
<td><label for='job_title'>Job Title</label></td>
<td><input type='text' name='job_title' id='job_title' value='Prince of the Relm'></input></td></tr>
<td><label for='department'>Department</label></td>
<td><input type='text' name='department' id='department' value='Jewelry'></input></td></tr>
<td><label for='organization'>Organization</label></td>
<td><input type='text' name='organization' id='organization' value='Trinkets Unlimited'></input></td></tr>
<td><label for='work_address'>Work Address</label></td>
<td><input type='text' name='work_address' id='work_address' value=''></input></td></tr>
<td><label for='work_city'>Work City</label></td>
<td><input type='text' name='work_city' id='work_city' value=''></input></td></tr>
<td><label for='work_state'>Work State</label></td>
<td><input type='text' name='work_state' id='work_state' value=''></input></td></tr>
<td><label for='work_zip'>Work Zip</label></td>
<td><input type='text' name='work_zip' id='work_zip' value=''></input></td></tr>
<td><label for='work_phone'>Work Phone</label></td>
<td><input type='text' name='work_phone' id='work_phone' value=''></input></td></tr>
<td><label for='work_fax'>Work Fax</label></td>
<td><input type='text' name='work_fax' id='work_fax' value=''></input></td></tr>
<td><label for='work_email'>Work Email</label></td>
<td><input type='text' name='work_email' id='work_email' value=''></input></td></tr>
<td><label for='website'>Website</label></td>
<td><input type='text' name='website' id='website' value=''></input></td></tr>
<td><label for='home_notes'>Home Notes</label></td>
<td><textarea name='home_notes' id='home_notes'  rows=5 cols=81> '  Hello There.  ' </textarea></td></tr>
<td><label for='work_notes'>Work Notes</label></td>
<td><textarea name='work_notes' id='work_notes'  rows=5 cols=81> ' Hello back to you. ' </textarea></td></tr>
<tr><td><input type='submit' class='hov'  name='submit' value='Save Contact Data'></input></td></tr>
<div id='inputForm'></div>
<div id='controls'>
<div id='rbox'>
<div id='rbox2'>
    [Name_ID] => 1172
    [First_Name] => Alfred H.
    [Last_Name] => Google707
    [Display_Name] => Google707, Alfred H.
    [Home_Phone] => 208.123.5555
    [Home_Cell] => 509.123.5555
    [Home_Email] => alfredh@net.com
    [Home_Address] => 1234 MyRoad
    [Home_City] => Pigeon
    [Home_State] => CO
    [Home_Zip] => 23456
    [Job_Title] => Prince of the Relm
    [Department] => Jewelry
    [Organization] => Trinkets Unlimited
    [Home_Notes] =>   Hello There.  
    [Work_Notes] =>  Hello back to you. 

hey dude, one thing is bugging me, if you use json to return values why are you commenting json_encode($rowsSaved)? and just so you know everything you echo or printf is returned when call ajax


btw i find it hard to debug here in my end because of your includes, i don't them files you know, well nevermind i don't know if im helping you but i don't really know what you want to achieve


Thanks vaultdweller,

I had to leave town for the day.

Tomorrow I will send you the files you need to run this properly. I actually thought about not giving you all the necessary files during my travels today. Sorry I wasted your time.

Regarding your comment re: echo or printf, you are saying, I think, that what I am trying to do is not possible. That is to call revise.php with an ajax call ==> $.post("#revise.php", {.....)<== and try to use printf to display a table/form. Do I read you correctly. This is exactly what I am trying to do.

Talk tomorrow.

Thanks for your help and time, RP

PS Yes you are helping me. Even a negative outcome is letting me progress.


Hi, Vaultdweller,

After thinking about this again and studying more questions/answers on forums and, before I went all out and sent you all the files for this application, I followed your advice and changed the $.post call with a slight variation. That and acting on your comment about PHP not being compatible with Jquery re: echo and printf WE seem to have solved my problem.

$.post("revise.php", {id: revId, revData: revFlg, dName: dispName}, showResultsFromServer, "json");


$.post("revise.php", {id: revId, revData: revFlg, dName: dispName}, showResultsFromServer, "html");

Now it works the way I expected it to.

Thanks again for all your time and help.



glad to help my friend, actually im just really giving you advise, it was really you who solved the problem :) , btw is this problem solved? one way of saying thanks is marking this thread solved :D



Thanks Vaultdweller,

I put "Solved:" in the title of my last post. I thought I saw an icon somewhere that will put "Solved" in the proper place in the message but it must have been another forum.


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.