...

View Full Version : Passing the result of a function to mysql



acemcleod
04-26-2011, 07:17 PM
Hello folks, generally I prefer to find my answers via google or use help files but so far can't find anything to help me on this. For reference sake I am heavily modifying the Flex Test Drive App since it pretty much facilitates what I am trying to do, which is build an issue tracking application for my company. Its not software, more like customer calls to complain about something. Anyhow, I have created an InputDate field that I have written a function to populate with the currentDate, however the value of the function is not being passed to the database. How do I get a value generated by a function to post to a mysql database?



//Here is the function that adds issues to the database
protected function button_clickHandler(event:MouseEvent):void
{
issues.iDate = iDateTextInput.text;
issues.customerFname = customerFnameTextInput.text;
issues.customerLname = customerLnameTextInput.text;
issues.phNum = phNumTextInput.text;
issues.customerAddress = customerAddressTextInput.text;
issues.customerCity = customerCityTextInput.text;
issues.customerState = customerStateTextInput.text;
issues.iType = iTypeTextInput.text;
issues.iNote = iNoteTextInput.text;
issues.binQ = binQTextInput.text;
issues.dDate = dDateTextInput.text;
issues.rtNum = rtNumTextInput.text;
issues.rtSupervisor = rtSupervisorTextInput.text;
issues.iClosed = iClosedTextInput.text;
issues.rDate = rDateTextInput.text;
issues.rNote = rNoteTextInput.text;

if(issues.tktNum==0){
createIssuetableResult.token = issuetableService.createIssuetable(Issues);
}
else{
updateIssuetableResult.token = issuetableService.updateIssuetable(Issues);
}
}

//Function to get today's date and return a string
private function currentDateToString():String{
var CurrentDate:Date = new Date();
return dateFormatter.format(CurrentDate);
}

//This is the specific form label that displays the result of the function
<mx:FormItem label="Input Date:">
<s:Label id="iDateTextInput" text="currentDateToString()}"/>
</mx:FormItem>

I appreciate any help. Thanks!

PappaJohn
04-26-2011, 07:25 PM
It would seem that the issuetableService object actually adds to / updates the database. We'd need to see the code for that object.

acemcleod
04-26-2011, 08:19 PM
Here is the php function that is used to create the issue


public function createIssuetable($item) {
$stmt = mysqli_prepare($this->connection,
"INSERT INTO issuetable (
iDate, customerFname, customerLname,
phNum, customerAddress, customerCity,
customerState, iType, iNote, rNote, rDate,
rtNum, binQ, dDate, iClosed, rtSupervisor)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$this->throwExceptionOnError();


mysqli_bind_param($stmt, 'sssssssssssiisss', $item->iDate, $item->customerFname, $item->customerLname,
$item->phNum, $item->customerAddress, $item->customerCity,
$item->customerState, $item->iType, $item->iNote, $item->rNote,
$item->rDate, $item->rtNum, $item->binQ, $item->dDate, $item->iClosed, $item->rtSupervisor);
$this->throwExceptionOnError();


mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();


$autoid = mysqli_stmt_insert_id($stmt);


mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);

return $autoid;
}

PappaJohn
04-27-2011, 04:22 AM
Well that's great, but not quite what I asked for - no matter, I just noticed the probable culprit.



if(issues.tktNum==0){
createIssuetableResult.token = issuetableService.createIssuetable(Issues);
}
else{
updateIssuetableResult.token = issuetableService.updateIssuetable(Issues);
}
}

Note the items in red. AS is case-sensitive, issues is not the same as Issues. I'm thinking you want:


if(issues.tktNum==0){
createIssuetableResult.token = issuetableService.createIssuetable(issues);
}
else{
updateIssuetableResult.token = issuetableService.updateIssuetable(issues);
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum