[SOLVED] Need some direction on how I can determine ...
Posted: Tue Feb 06, 2007 10:17 am
Ok so the deal is that I am trying to save some data from a form, the data I'm having issues with is referred to as community data.
Now for each contact, they can be associated to none, some , many different communities. For each community they belong to they can have several attributes go along with it... Ok now for the code
I'm using a foreach to iterate through the community data that gets posted from the previous page...
So here I'm trying to see if there is an existing record...
And trying some logic here...
Basically it's not working right, I've tried many different approaches, but either get results saying there are records (when there isn't) or creating new records when some exist already.
I apologize for the noobish coding, just getting into php so please excuse.
What I need it to do is update a record with the community data if it exists or make a new if it doesn't.
I also need to mention that the community names (CName) and user ID (ContactID) will be unique for each record. Basically for each ContactID each CName must be unique
Thanks everyone.
Wade
Now for each contact, they can be associated to none, some , many different communities. For each community they belong to they can have several attributes go along with it... Ok now for the code
I'm using a foreach to iterate through the community data that gets posted from the previous page...
Code: Select all
foreach($rowData as $v){
if($v["HOContact"]) {$v["HOContact"] = 1;} else {$v["HOContact"] = 0;}
if($v["HOAcctContact"]) {$v["HOAcctContact"] = 1;} else {$v["HOAcctContact"] = 0;}
if($v["MUAreaMgr"]) {$v["MUAreaMgr"] = 1;} else {$v["MUAreaMgr"] = 0;}
if($v["StAreaMgr"]) {$v["StAreaMgr"] = 1;} else {$v["StAreaMgr"] = 0;}
if($v["MFAreaMgr"]) {$v["MFAreaMgr"] = 1;} else {$v["MFAreaMgr"] = 0;}
if($v["SCContact"]) {$v["SCContact"] = 1;} else {$v["SCContact"] = 0;}
if($v["VMAttendee"]) {$v["VMAttendee"] = 1;} else {$v["VMAttendee"] = 0;}
if($v["ConMgr"]) {$v["ConMgr"] = 1;} else {$v["ConMgr"] = 0;}
if($v["SiteSuper"]) {$v["SiteSuper"] = 1;} else {$v["SiteSuper"] = 0;}
if($v["SiteSuperAsst"]) {$v["SiteSuperAsst"] = 1;} else {$v["SiteSuperAsst"] = 0;}
if($v["VIPOpenInvite"]) {$v["VIPOpenInvite"] = 1;} else {$v["VIPOpenInvite"] = 0;}
if($v["CCCLunchInvite"]) {$v["CCCLunchInvite"] = 1;} else {$v["CCCLunchInvite"] = 0;}Code: Select all
$query99 = "SELECT * FROM communities WHERE ContactID=" . $ContactID . " AND CName='" . $v["CName"] . "'";
$result99 = mysql_query ($query99)or die ("I cannot connect to the database because: " . mysql_error());
$row99 = mysql_fetch_array($result99, MYSQL_ASSOC);Code: Select all
if ($row99["CName"] = $v["CName"]){
$query2 = "UPDATE communities SET HOContact='" . $v["HOContact"] . "',HOAcctContact='" . $v["HOAcctContact"] .
"',MUAreaMgr='" . $v["MUAreaMgr"] . "',StAreaMgr='" . $v["StAreaMgr"] . "',MFAreaMgr='" . $v["MFAreaMgr"] .
"',SCContact='" . $v["SCContact"] . "',VMAttendee='" . $v["VMAttendee"] . "',ConMgr='" . $v["ConMgr"] .
"',SiteSuper='" . $v["SiteSuper"] . "',SiteSuperAsst='" . $v["SiteSuperAsst"] .
"',VIPOpenInvite='" . $v["VIPOpenInvite"] . "',CCCLunchInvite='" . $v["CCCLunchInvite"] . "' WHERE CName='" . $v["CName"] . "' AND ContactID=" . $ContactID;
echo("Existing record SQL for Communities Table: " . $query2 . "<br><br>");
$result2 = mysql_query ($query2) or die ("I couldn't save the record to the database because: " . mysql_error());
} else {
$query2 = "INSERT INTO communities (CName,ContactID,HOContact,HOAcctContact,MUAreaMgr,StAreaMgr,MFAreaMgr,SCContact,VMAttendee,ConMgr,SiteSuper,SiteSuperAsst,VIPOpenInvite,CCCLunchInvite)
VALUES
(
'" . $v["CName"] . "',
'" . $ContactID . "',
'" . $v["HOContact"] . "',
'" . $v["HOAcctContact"] . "',
'" . $v["MUAreaMgr"] . "',
'" . $v["StAreaMgr"] . "',
'" . $v["MFAreaMgr"] . "',
'" . $v["SCContact"] . "',
'" . $v["VMAttendee"] . "',
'" . $v["ConMgr"] . "',
'" . $v["SiteSuper"] . "',
'" . $v["SiteSuperAsst"] . "',
'" . $v["VIPOpenInvite"] . "',
'" . $v["CCCLunchInvite"] . "'
)";
echo("New record SQL for Communities Table: " . $query2 . "<br><br>");
$result2 = mysql_query ($query2) or die ("I couldn't save the record to the database because: " . mysql_error());
}
}I apologize for the noobish coding, just getting into php so please excuse.
What I need it to do is update a record with the community data if it exists or make a new if it doesn't.
I also need to mention that the community names (CName) and user ID (ContactID) will be unique for each record. Basically for each ContactID each CName must be unique
Thanks everyone.
Wade