i m designing a CRM for real Estate company. dis is d code i hve used to log d details of client :-

<?php
session_start();

if($_SESSION['Name']=='')
{
echo "<script>window.location='login.html';</script>";
}
?>
<!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>CALL LOG DETAILS</title>

</head>
<?php
include('connection.php');
/*$username="root";
$password="";
$database="_relocateeasily";
mysql_connect(localhost,$username,$password);

mysql_select_db($database) or die("Unable to select database");*/
$z=array();

if($_POST['submit']==AllRequirementsTaken)
{

$bor=$_POST['choices'];
$Locality=serialize($_POST['Location']);
if($_POST['Location']!=0)
{
foreach($_POST['Location'] as $zonec)
{
$query="select ZoneName from zone1 where LocationName='$zonec'";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
    if($num!=0)
    {
        while($i<$num) {
        $zone1=mysql_result($result,$i,"ZoneName");
        $i++;
    }
    }
global $z;
array_push($z,$zone1);
}

$z = array_unique($z);
$zone=serialize($z);
}
$SalesCoordinator=$_POST['coordinator'];
$SalesExecutive=$_POST['SalesExecutive'];
$OtherPreferences=$_POST['OtherPreferences'];
$BHK=serialize($_POST['BHK']);
$FoodType=$_POST['choice3'];
$Parking=serialize($_POST['choice5']);
$ExpectedMove_inDate=$_POST['ExpectedMove_inDate'];
$Budget=$_POST['Budget'];
$MaxBudget=$_POST['MaxBudget'];
$ResudenceType=serialize($_POST['choice6']);
$ClientType=$_POST['choice2'];
$Furnishing=$_POST['choice4'];
$NextContactDate=$_POST['NextContactDate'];
$NextContactTime=$_POST['NextContactTime'];
$TADate=$_POST['TADate'];
$TATime=$_POST['TATime'];
$NoOfPeople=$_POST['NoOfPeople'];
$callnotes=$_POST['CallNotes'];
$Name=$_POST['Name'];   
$Address=$_POST['Address'];
$Company=$_POST['Company'];
$CompanyLocality=$_POST['CompanyLocality'];
$MobileNo=$_POST['MobileNo'];
$OtherNo=$_POST['OtherNo'];
$EmailID=$_POST['EmailID'];
$MarketingStrategy=$_POST['choice7'];
$CameVia=$_POST['choice8'];
$CameOn=$_POST['CameOn'];
$Notes=$_POST['Notes'];



    $query1="INSERT INTO clientrequirement (Buy,Locality,Zone,SalesCoordinator,SalesExecutive,OtherPreferences,BHK,FoodType, Parking,ExpectedMove_inDate,Budget,MaxBudget,ResidenceType,ClientType,Furnishing,NextContactDate,NextContactTime,TADate,TATime,NoOfPeople,CallNotes,status) VALUES ('$bor','$Locality','$zone', '$SalesCoordinator', '$SalesExecutive', '$OtherPreferences', '$BHK', '$FoodType', '$Parking', '$ExpectedMove_inDate', '$Budget','$MaxBudget', '$ResudenceType', '$ClientType', '$Furnishing', '$NextContactDate', '$NextContactTime', '$TADate', '$TATime','$NoOfPeople', '$callnotes','1')";
        $sql=mysql_query($query1);


if(!($sql))
{echo "not able ";}


$query2="INSERT INTO clientdetails ( Name,Address, Company, CompanyLocality, MobileNo, OtherNo, EmailID, MarketingStrategy, CameVia,CameOn,Notes,status) VALUES ('$Name','$Address','$Company','$CompanyLocality','$MobileNo','$OtherNo','$EmailID', '$MarketingStrategy','$CameVia','$CameOn','$Notes','1')";
mysql_query($query2);
$query="SELECT MAX(ClientID) as id FROM clientdetails";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$id = $row['id'];
$query3="insert into calllog(ClientID,nextcalldate,nextcalltime,callnotes,status) values('$id','$NextContactDate', '$NextContactTime', '$callnotes','1')";
mysql_query($query3);
echo "<script>window.location='index.php'</script>";
}
if($_POST['submit']==YetRequirementsTaken)
{
$bor=$_POST['choices'];
$Locality=serialize($_POST['Location']);
if($_POST['Location']!=0)
{
foreach($_POST['Location'] as $zonec)
{
$query="select ZoneName from zone1 where LocationName='$zonec'";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
    if($num!=0)
    {
        while($i<$num) {
        $zone1=mysql_result($result,$i,"ZoneName");
        $i++;
    }
    }
global $z;
array_push($z,$zone1);
}

$z = array_unique($z);
$zone=serialize($z);
}
$SalesCoordinator=$_POST['coordinator'];
$SalesExecutive=$_POST['SalesExecutive'];
$OtherPreferences=$_POST['OtherPreferences'];
$BHK=serialize($_POST['BHK']);
$FoodType=$_POST['choice3'];
$Parking=serialize($_POST['choice5']);
$ExpectedMove_inDate=$_POST['ExpectedMove_inDate'];
$Budget=$_POST['Budget'];
$MaxBudget=$_POST['MaxBudget'];
$ResudenceType=$_POST['choice6'];
$ClientType=$_POST['choice2'];
$Furnishing=$_POST['choice4'];
$NextContactDate=$_POST['NextContactDate'];
$NextContactTime=$_POST['NextContactTime'];
$TADate=$_POST['TADate'];
$TATime=$_POST['TATime'];
$NoOfPeople=$_POST['NoOfPeople'];
$callnotes=$_POST['CallNotes'];
$Name=$_POST['Name'];   
$Address=$_POST['Address'];
$Company=$_POST['Company'];
$CompanyLocality=$_POST['CompanyLocality'];
$MobileNo=$_POST['MobileNo'];
$OtherNo=$_POST['OtherNo'];
$EmailID=$_POST['EmailID'];
$MarketingStrategy=$_POST['choice7'];
$CameVia=$_POST['choice8'];
$CameOn=$_POST['CameOn'];
$Notes=$_POST['Notes'];
 $query1="INSERT INTO clientrequirement (Buy,Locality,Zone,SalesCoordinator,SalesExecutive,OtherPreferences,BHK,FoodType, Parking,ExpectedMove_inDate,Budget,MaxBudget,ResidenceType,ClientType,Furnishing,NextContactDate,NextContactTime,TADate,TATime,NoOfPeople,CallNotes,status) VALUES ('$bor','$Locality','$zone', '$SalesCoordinator', '$SalesExecutive', '$OtherPreferences', '$BHK', '$FoodType', '$Parking', '$ExpectedMove_inDate', '$Budget','$MaxBudget', '$ResudenceType', '$ClientType', '$Furnishing', '$NextContactDate', '$NextContactTime', '$TADate', '$TATime','$NoOfPeople', '$callnotes','0')";
        $sql=mysql_query($query1);


$query2="INSERT INTO clientdetails ( Name,Address, Company, CompanyLocality, MobileNo, OtherNo, EmailID, MarketingStrategy, CameVia,CameOn,Notes,status) VALUES ('$Name','$Address','$Company','$CompanyLocality','$MobileNo','$OtherNo','$EmailID', '$MarketingStrategy','$CameVia','$CameOn','$Notes','0')";
mysql_query($query2);
$query="SELECT MAX(ClientID) as id FROM clientdetails";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$id = $row['id'];
$query3="insert into calllog(ClientID,nextcalldate,nextcalltime,callnotes,status) values('$id','$NextContactDate', '$NextContactTime', '$callnotes','1')";
mysql_query($query3);
 echo "<script>window.location='index.php'</script>";

}
if($_POST['submit']==DUMP)
{
$bor=$_POST['choices'];
$Locality=serialize($_POST['Location']);
if($_POST['Location']!=0)
{
foreach($_POST['Location'] as $zonec)
{
$query="select ZoneName from zone1 where LocationName='$zonec'";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
    if($num!=0)
    {
        while($i<$num) {
        $zone1=mysql_result($result,$i,"ZoneName");
        $i++;
    }
    }
global $z;
array_push($z,$zone1);
}

$z = array_unique($z);
$zone=serialize($z);
}
$DumpReason=$_POST['dump'];
$DumpDetails=$_POST['DumpDetails'];
$SalesCoordinator=$_POST['coordinator'];
$SalesExecutive=$_POST['SalesExecutive'];
$OtherPreferences=$_POST['OtherPreferences'];
$BHK=serialize($_POST['BHK']);
$FoodType=$_POST['choice3'];
$Parking=serialize($_POST['choice5']);
$ExpectedMove_inDate=$_POST['ExpectedMove_inDate'];
$Budget=$_POST['Budget'];
$MaxBudget=$_POST['MaxBudget'];
$ResudenceType=$_POST['choice6'];
$ClientType=$_POST['choice2'];
$Furnishing=$_POST['choice4'];
$NextContactDate=$_POST['NextContactDate'];
$NextContactTime=$_POST['NextContactTime'];
$TADate=$_POST['TADate'];
$TATime=$_POST['TATime'];
$NoOfPeople=$_POST['NoOfPeople'];
$callnotes=$_POST['CallNotes'];
$Name=$_POST['Name'];   
$Address=$_POST['Address'];
$Company=$_POST['Company'];
$CompanyLocality=$_POST['CompanyLocality'];
$MobileNo=$_POST['MobileNo'];
$OtherNo=$_POST['OtherNo'];
$EmailID=$_POST['EmailID'];
$MarketingStrategy=$_POST['choice7'];
$CameVia=$_POST['choice8'];
$CameOn=$_POST['CameOn'];
$Notes=$_POST['Notes'];
 $query1="INSERT INTO clientrequirement (Buy,Locality,Zone,SalesCoordinator,SalesExecutive,OtherPreferences,BHK,FoodType, Parking,ExpectedMove_inDate,Budget,MaxBudget,ResidenceType,ClientType,Furnishing,NextContactDate,NextContactTime,TADate,TATime,NoOfPeople,CallNotes,status,DumpReason,DumpDetails,DumpDate) VALUES ('$bor','$Locality','$zone', '$SalesCoordinator', '$SalesExecutive', '$OtherPreferences', '$BHK', '$FoodType', '$Parking', '$ExpectedMove_inDate', '$Budget','$MaxBudget', '$ResudenceType', '$ClientType', '$Furnishing', '$NextContactDate', '$NextContactTime', '$TADate', '$TATime','$NoOfPeople', '$callnotes','4','$DumpReason','$DumpDetails','$CameOn')";
        $sql=mysql_query($query1);
$query2="INSERT INTO clientdetails ( Name,Address, Company, CompanyLocality, MobileNo, OtherNo, EmailID, MarketingStrategy, CameVia,CameOn,Notes,status) VALUES ('$Name','$Address','$Company','$CompanyLocality','$MobileNo','$OtherNo','$EmailID', '$MarketingStrategy','$CameVia','$CameOn','$Notes','4')";
mysql_query($query2);
$query="SELECT MAX(ClientID) as id FROM clientdetails";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$id = $row['id'];
$query3="insert into calllog(ClientID,nextcalldate,nextcalltime,callnotes,status) values('$id','$NextContactDate', '$NextContactTime', '$callnotes','1')";
mysql_query($query3);

}

if($_POST['submit']==CLEAR)
{
}
?>
<body onload="count()">
<form method="GET" action="" name="form" >
<link href="styles2.css" rel="stylesheet" type="text/css" media="screen" />
<link rel="stylesheet" type="text/css" href="view1.css" media="all">
<div style="position:absolute; right:70px; top:70px">
<table ><tr>
<td align="right" width="680"><div style="color:#CC0000;">Select The Field To sort:</div></td><td ><select  id="select2" name="s" size="1" style="width:150px;">
<option selected="selected"></option>
<OPTION value="Name">Name</OPTION>
<OPTION value="MobileNo">Mobile No</OPTION>
<OPTION value="SalesExecutive">Sales Executive</OPTION>
<OPTION value="CallNotes"> Call Notes</OPTION>
</select>
<a href="javascript:;" onclick="sort1()">GO</a></td><td></td><td>
<a href="signout.php">SIGNOUT</a></td></tr></table>
<input type="hidden" value="ASC"  id="order" />
</div>

        <div id="menu5">
        <ul>
        <table><tr><td ><li><a href="client1.php">NEW CLIENT</a></li></td>
        <td><li><a href="TakeRequirement.php">TReq</a></li></td>
       <td><li><a href="calllog.php">CLIENT LOG</a></li></td>
        <td><li><a href="appointmentlist.php">APPT</a></li></td>
        <td><li><a href="dumplist.php">DUMP LIst</a></li></td>
        <td><li><a href="postdeal2.php">POST DEAL</a></li></td>
      <td><li><a href="reports.php">REPORTS</a></li></td>
       <td><li><a href="s1.php">SE</a></li></td></tr>
        </table>
        </ul>
        </div>
<div id="name">
<?php
$query="SELECT DATE_FORMAT(c.nextcalldate,'%d-%b-%y') as ncdate,c1.ClientId,c1.Name,c1.MobileNo,c2.SalesExecutive,c.nextcalltime,c.nextcalldate,c.callnotes,c2.SalesCoordinator,c.status FROM clientdetails AS c1 INNER JOIN clientrequirement AS c2 inner join calllog as c WHERE c1.ClientID = c2.ClientID and c1.ClientID = c.ClientID and c1.status=1 and c2.status=1 and  c1.status=c2.status and c.status=1 and c.status=c2.status ORDER BY c.nextcalldate ,c.nextcalltime";
$result = mysql_query($query);
$d = mysql_num_rows($result);
if($d>=1)
{
$i=0;
print "<div id=\"count1\"></div>";
print"<div id=\"content\" style=\"position:absolute;left:5px;top:100px;margin:20px;width:800px;height:80px;z-index:14;\" align=\"left\"><br />"; 
print "<h2 align=center>CLIENT LOG DETAILS</h2>";
print "<table border=0 align=center><tr bgcolor='#8B8B83'><th><div  style=\"width:150px\">NAME </div></th><th>MOBILE NO  </th><th><div style=\"width:100px\">SE</div></th><th><div style=\"width:80px\">NC DATE </div> </th><th>NC TIME</th><th>CALL NOTES </th></tr></tr>";
while($i<$d) 
{
   $id=mysql_result($result,$i,"ClientID"); 
   $name=mysql_result($result,$i,"Name");
   $mobileno=mysql_result($result,$i,"MobileNo");
   $sc=mysql_result($result,$i,"SalesCoordinator"); 
   $se=mysql_result($result,$i,"SalesExecutive"); 
   $nd=mysql_result($result,$i,"nextcalldate");
   $ncd=mysql_result($result,$i,"ncdate");
   $nt=mysql_result($result,$i,"nextcalltime");
   $c=mysql_result($result,$i,"callnotes");
   $time=date("g:i a", strtotime("$nt"));
   $n="notes".$i;
   $d1="date".$i;
   $t1="time".$i;
   $e="executive".$i;
print "<tr bgcolor='#CDCDC1' align=center><td><a href=\"details.php?id=$id\" >$name</td><td align=center><a href=\"javascript:;\" onclick=\"window.open('todaysappt.php?id=$id','mywindow','width=350,height=200,left=100,top=100,screenX=100,screenY=300') \">$mobileno</a></td><td>$se</td><td>";
if($nd>date("Y-m-d"))
{
print "<input type=\"text\" size =\"8\" id=\"$d1\" name=\"NextContactDate\" value=\"$ncd\"/>";
}
if($nd<date("Y-m-d"))
{
print "<input type=\"text\" class=\"box\" size =\"8\" id=\"$d1\" name=\"NextContactDate\" value=\"$ncd\"/>";
}
if($nd==date("Y-m-d"))
{
print "<input type=\"text\" class=\"box1\" size =\"8\" id=\"$d1\" name=\"NextContactDate\" value=\"$ncd\"/>";
}
print "</td><td><input type=\"text\" size =\"6\" id=\"$t1\" name=\"NextContactTime\" value=\"$time\"/><td><input type=\"text\" id=\"$n\"      name=\"CallNotes\" size=\"30\" value=\"$c\"/></td><td><a href=\"javascript:;\" onclick=\"updatecalllog($id,'$n','$d1','$t1')\">update</td></tr>";
   $i++;

 }


print "</table>";
print "</div>";
}
?>
</div>
<?php
$query="SELECT ClientID,Name,SalesExecutive,ApptNotes from todaysappt";
$result = mysql_query($query);
$d = mysql_num_rows($result);
if($d>=1)
{
$i=0;
print "<div id=\"count1\"></div>";
print"<div id=\"content\" style=\"position:absolute;left:800px;top:100px;margin:20px;width:800px;height:80px;z-index:14;\" align=\"left\"><br />"; 
print "<h2>TODAYS APPT DETAILS</h2>";
print "<table border=0 align=center><tr bgcolor='#8B8B83'><th><div  style=\"width:150px\">NAME </div></th><th><div style=\"width:100px\">SE</div></th><th><div style=\"width:150px\">APPT NOTES</div> </th></tr>";
while($i<$d) 
{
   $id=mysql_result($result,$i,"ClientID");
   $name=mysql_result($result,$i,"Name");
   $se=mysql_result($result,$i,"SalesExecutive"); 
   $notes=mysql_result($result,$i,"ApptNotes");
?>
<tr bgcolor='#CDCDC1' align=center><td><a href="details.php?id=<?=$id?>"><?=$name?></a></td><td><?=$se?></td><td><input type="text"name="ApptNotes" value="<?=$notes?>" onchange="updateappt('APPtNotes',this.value,<?=$id?>)" /></td><td><a href='deletetodaysappt.php?id=<?=$id?>'>delete</a></td></tr>
<?php
   $i++;

 }


print "</table>";
print "</div>";
}
?>
</form>
</body>
</html>
<script type="text/javascript">
function updatecalllog(id,notes,date,time)
{
var val = document.getElementById(notes).value;
var d = document.getElementById(date).value;
var t = document.getElementById(time).value;

var url="callnotesupdate.php?id="+id+"&cn="+val+"&date1="+d+"&time1="+t+"&timeid="+(Math.random()*100000);

if(window.XMLHttpRequest)
 {


    req=new XMLHttpRequest();
    req.open("GET",url,true);
    req.send(null);
 }
 else if(window.ActiveXObject)
 {
    req=new ActiveXObject("MSXML2.XMLHTTP.3.0");
    req.open("GET",url,true);
    req.send(null);
  }
}
function sort1()
{
var val=document.getElementById("select2").value;
var order=document.getElementById("order");
 var url="sort.php?field="+val+"&order="+order.value+"&timeid="+(Math.random()*100000);
if(order.value=='ASC')
{
  order.value='DESC';
  }
  else if(order.value=='DESC')
  {
  order.value='ASC';
  }
if(window.XMLHttpRequest)
 {


    req=new XMLHttpRequest();
    req.open("GET",url,true);
    req.send(null);
 }
 else if(window.ActiveXObject)
 {
    req=new ActiveXObject("MSXML2.XMLHTTP.3.0");
    req.open("GET",url,true);
    req.send(null);
  }
  req.onreadystatechange = function ()
  {
if(req.readyState==4)
{
      document.getElementById('name').innerHTML=req.responseText;
}
}
}
function count()
{
var url1="count.php?timeid="+(Math.random()*100000);

if(window.XMLHttpRequest)
 {


    req=new XMLHttpRequest();
    req.open("GET",url1,true);
    req.send(null);
 }
 else if(window.ActiveXObject)
 {
    req=new ActiveXObject("MSXML2.XMLHTTP.3.0");
    req.open("GET",url1,true);
    req.send(null);
  }
  req.onreadystatechange = function ()
  {
if(req.readyState==4)
{
      document.getElementById('count1').innerHTML=req.responseText;
}
}
}
function updateappt(name,value,id)
{
var url="todaysapptupdate.php?id="+id+"&name="+name+"&value="+value+"&timeid="+(Math.random()*100000);
if(window.XMLHttpRequest)
 {
    req=new XMLHttpRequest();
    req.open("GET",url,true);
    req.send(null);
 }
 else if(window.ActiveXObject)
 {
    req=new ActiveXObject("MSXML2.XMLHTTP.3.0");
    req.open("GET",url,true);
    req.send(null);
  }

}
</script>

now My Mysql database consist of d fileds such as:

ClientID,Locality,Zone,CRA,GroundFloor,TopFloor,Amenities,OtherPreferences,BHK,MINBudget,MaxBudget,Vastu,NextContactDate,NextContactTime,MinSqft,CallNotes,status,DumpDetails,DumpReason,DumpDate.                           

In d above code, d fields r different and query is embedded wid old db fields.

I want to edit dis fields correctly wid d above said fields

i hve tried a lot bt m getting error.

so plz reply n try to correct d code

Thanx :)

Just print the sql string line of insert , update each. You will be able to know where the error is, and you may refer jquery.com ajax post methods to make your ajax work easy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.