swatisonee
01-04-2007, 11:37 AM
Hi,
This is what my code is supposed to do :
a.)Select a customer (say. CompanyD) from db table A. This gives us a variable $cid
b.)Select an address (say. LocationX) from table B (which has a field called $cid corresp. to companies in Table A). This will result in variable $caid
c.)Add the name of a person who works in the LocationX office of CompanyD. This will generate a new record, which will be identified by a field CCID (variable $ccid)
d.)Both customer and address can change for each record. This data will go into table C
Table C also has fields CID, CAID and resp. values of ($cid and $caid)
Now, I have got the foll. code but the addForm function and the code thereafter is plain wrong and i dont know how to set it right . Would someone be able to have a look ? Thanks ! Or if someone knows a more efficient way to code, i dont mind re-doing the whole thing.
I have just put in 1 variable -mobile to test it out and will add the others like name etc once i get this working.
Thanks ! Swati
<?
session_cache_limiter('public');
include ("../include/session.php");
if(!isset($_SESSION['userid'])){
echo "<center><font face='Verdana' size='2' color=red>Sorry, Please login and use this page </font></center>";
exit;}
$userid = $_SESSION['userid'];
?>
<?php
function citySelect ($current, $dis='') {
$sql = "SELECT CITYID, City
FROM Cities
ORDER BY City";
$res = mysql_query($sql) or die(mysql_error());
$str = "<SELECT name='cityid' $dis>\n";
while (list($id,$name)=mysql_fetch_row($res)) {
$selected = $id==$current ? 'selected' : '';
$str .= "<option value=$id $selected>$name</option>\n";
}
$str .= "</select>\n";
return $str;
}
function companyList($co) {
$sql = "SELECT CID, Company
FROM Customers
WHERE Company LIKE '%$co%'
ORDER BY Company";
$res = mysql_query($sql) or die(mysql_error());
$str = "<table cellspacing='0' cellpadding='2' border='0'>\n";
while (list($id,$name)=mysql_fetch_row($res)) {
$str .= "<tr><td><a href='?action=select&company=$id'>Select</td><td>$name</td></tr>\n";
}
$str .= "</table>";
return $str;
}
function addressList($cid) {
global $fmCompany;
$sql = "SELECT a.CAID, a.Street, a.CITYID, a.Pincode, a.Areacode, a.Phone, a.Fax, a.Email, c.Company
FROM Custaddress a
INNER JOIN Customers c ON a.CID = c.CID
WHERE a.CID = '$cid'";
$res = mysql_query($sql) or die(mysql_error());
$str = '<form method="post">
<input type="hidden" name="fname" value="fmAddress">
<table border="1"><center><font face=Verdana size=2 color=white>
<tr><th>Street</th><th>City</th><th>Pincode</th><th>Areacode</th><th>Phone</th><th>Fax</th><th>Email</th>
<th>Select</th></tr>';
while (list($caid, $st, $city, $pc, $ac, $ph, $fax, $em, $co)=mysql_fetch_row($res)) {
$fmCompany = $co;
$str .= "<tr><td>$st</td><td>" . citySelect($city, 'disabled') . "</td><td>$pc</td><td>$ac</td><td>$ph</td><td>$fax</td><td>$em</td>
<td><input type='radio' name='address' value='$caid'></td></tr>";
}
$str .= '</table><br>
<input type="submit" name="action" value="Select address where the new person can be contacted">
</form>';
return $str;
}
function addForm() {
global $fmCompany;
$str = "<form method='post'>
<input type='hidden' name='caid' value='$caid'>
<input type='hidden' name='cid' value='$cid'>
<table border='1'><center><font face=Verdana size=2 color=white>";
$fmCompany = $co;
$str .= "<tr><td>Mobile</td><td><input type='text' value='$mobile' size='100'></td></tr>
<tr><td> </td><td><input type='submit' name='action' value='INSERT'></td></tr>";
$str .= '</table></form>';
return $str;
$sql = "INSERT INTO Custcontact (CID, CAID ,Mobile) VALUES ('$cid', '$caid', '$mobile') WHERE CAID = '{$_POST['caid']}' AND CID = '{$_POST['cid']}' ";
mysql_query($sql);
echo "<center><font face=Verdana size=2 color=white>Contact Added";
}
if (isset($_REQUEST['action'])) {
switch ($_REQUEST['action']) {
case 'Search':
$srch = $_POST['srch'];
$fmCompany = stripslashes($_POST['srch']);
$body = companyList($srch);
break;
case 'select':
$body = addressList($_GET['company']);
break;
case 'Select address where the new person can be contacted':
$body = addForm($_POST['address']);
break;
case 'Insert':
$body = '';
addForm();
break;
}
}
else $body = '';
?>
<form name='fmSearch' method='POST'>
<input type="hidden" name="fname" value="fmSearch"><center><font face='Verdana' size='2' color=white>
Company Name <input type="text" name="srch" value="<?php echo $fmCompany ?>" size="80">
<input type="submit" name="action" value="Search">
</form>
<?php echo $body ?>
This is what my code is supposed to do :
a.)Select a customer (say. CompanyD) from db table A. This gives us a variable $cid
b.)Select an address (say. LocationX) from table B (which has a field called $cid corresp. to companies in Table A). This will result in variable $caid
c.)Add the name of a person who works in the LocationX office of CompanyD. This will generate a new record, which will be identified by a field CCID (variable $ccid)
d.)Both customer and address can change for each record. This data will go into table C
Table C also has fields CID, CAID and resp. values of ($cid and $caid)
Now, I have got the foll. code but the addForm function and the code thereafter is plain wrong and i dont know how to set it right . Would someone be able to have a look ? Thanks ! Or if someone knows a more efficient way to code, i dont mind re-doing the whole thing.
I have just put in 1 variable -mobile to test it out and will add the others like name etc once i get this working.
Thanks ! Swati
<?
session_cache_limiter('public');
include ("../include/session.php");
if(!isset($_SESSION['userid'])){
echo "<center><font face='Verdana' size='2' color=red>Sorry, Please login and use this page </font></center>";
exit;}
$userid = $_SESSION['userid'];
?>
<?php
function citySelect ($current, $dis='') {
$sql = "SELECT CITYID, City
FROM Cities
ORDER BY City";
$res = mysql_query($sql) or die(mysql_error());
$str = "<SELECT name='cityid' $dis>\n";
while (list($id,$name)=mysql_fetch_row($res)) {
$selected = $id==$current ? 'selected' : '';
$str .= "<option value=$id $selected>$name</option>\n";
}
$str .= "</select>\n";
return $str;
}
function companyList($co) {
$sql = "SELECT CID, Company
FROM Customers
WHERE Company LIKE '%$co%'
ORDER BY Company";
$res = mysql_query($sql) or die(mysql_error());
$str = "<table cellspacing='0' cellpadding='2' border='0'>\n";
while (list($id,$name)=mysql_fetch_row($res)) {
$str .= "<tr><td><a href='?action=select&company=$id'>Select</td><td>$name</td></tr>\n";
}
$str .= "</table>";
return $str;
}
function addressList($cid) {
global $fmCompany;
$sql = "SELECT a.CAID, a.Street, a.CITYID, a.Pincode, a.Areacode, a.Phone, a.Fax, a.Email, c.Company
FROM Custaddress a
INNER JOIN Customers c ON a.CID = c.CID
WHERE a.CID = '$cid'";
$res = mysql_query($sql) or die(mysql_error());
$str = '<form method="post">
<input type="hidden" name="fname" value="fmAddress">
<table border="1"><center><font face=Verdana size=2 color=white>
<tr><th>Street</th><th>City</th><th>Pincode</th><th>Areacode</th><th>Phone</th><th>Fax</th><th>Email</th>
<th>Select</th></tr>';
while (list($caid, $st, $city, $pc, $ac, $ph, $fax, $em, $co)=mysql_fetch_row($res)) {
$fmCompany = $co;
$str .= "<tr><td>$st</td><td>" . citySelect($city, 'disabled') . "</td><td>$pc</td><td>$ac</td><td>$ph</td><td>$fax</td><td>$em</td>
<td><input type='radio' name='address' value='$caid'></td></tr>";
}
$str .= '</table><br>
<input type="submit" name="action" value="Select address where the new person can be contacted">
</form>';
return $str;
}
function addForm() {
global $fmCompany;
$str = "<form method='post'>
<input type='hidden' name='caid' value='$caid'>
<input type='hidden' name='cid' value='$cid'>
<table border='1'><center><font face=Verdana size=2 color=white>";
$fmCompany = $co;
$str .= "<tr><td>Mobile</td><td><input type='text' value='$mobile' size='100'></td></tr>
<tr><td> </td><td><input type='submit' name='action' value='INSERT'></td></tr>";
$str .= '</table></form>';
return $str;
$sql = "INSERT INTO Custcontact (CID, CAID ,Mobile) VALUES ('$cid', '$caid', '$mobile') WHERE CAID = '{$_POST['caid']}' AND CID = '{$_POST['cid']}' ";
mysql_query($sql);
echo "<center><font face=Verdana size=2 color=white>Contact Added";
}
if (isset($_REQUEST['action'])) {
switch ($_REQUEST['action']) {
case 'Search':
$srch = $_POST['srch'];
$fmCompany = stripslashes($_POST['srch']);
$body = companyList($srch);
break;
case 'select':
$body = addressList($_GET['company']);
break;
case 'Select address where the new person can be contacted':
$body = addForm($_POST['address']);
break;
case 'Insert':
$body = '';
addForm();
break;
}
}
else $body = '';
?>
<form name='fmSearch' method='POST'>
<input type="hidden" name="fname" value="fmSearch"><center><font face='Verdana' size='2' color=white>
Company Name <input type="text" name="srch" value="<?php echo $fmCompany ?>" size="80">
<input type="submit" name="action" value="Search">
</form>
<?php echo $body ?>