Jump to content

This topic is 7541 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I followed the example from FX folder, create a list.php, detail.php, and apply to my database. Everything works fine.

I got stuck when I try to update a record. there is no error message, but the record cannot get updated. Here is my detail.php

<?php

require_once ("FX.php");

require_once("server_data.php");

$Query = new FX($serverIP, $webCompanionPort);

$Query->SetDBData("MyDB.fp5", "Form view");

$currentRecord = $_GET['ID'];

$Query->AddDBParam('-recid', $_GET['ID']);

$result = $Query->FMFind();

$currentKey = key($result['data']);

?>

<html>

<body bgcolor="#FFFFFF">

<form name="detail" action="edit.php?" method=POST>

<p>Injury Date:

<input name="Injury_Date" type="text" id="Injury_Date" value="<?php echo $result['data'][$currentKey]['Injury_Date'][0]; ?>" >

</p>

<p>Test Field:

<input name="test" type="text" value="<?php echo $result['data'][$currentKey]['test'][0]; ?>">

<input type="hidden" name="ID" value="<?php echo $currentRecord;?>">

<input type="submit" name="Submit" value="Update">

</p>

</form>

</html>

and here is my edit.php

<?php

require_once ("FX.php");

require_once("server_data.php");

$recordID = $_POST['ID'];

$Query = new FX($serverIP, $webCompanionPort);

$Query->SetDBData("MyDB.fp5", "Form view");

$Query->AddDBParam('-recid', $recordID);

if ($_POST['Submit']){

foreach ( $_POST as $key => $value)

{

$Query->AddDBParam($key, $value);

//$Query->AddDBParam('test', $_POST['test']);

//$Query->AddDBParam('Injury_Date', $_POST['Injury_Date']);

}

}

$returnData = $Query->FMEdit();

?>

As you can see in edit.php, if I use:

$Query->AddDBParam('test', $_POST['test']);

$Query->AddDBParam('Injury_Date', $_POST['Injury_Date']);

instead of the foreach()function, the record WILL get updated. So seems is the foreach() causes problem. (My php version: 4.3.6)

Can someone please help me? Thanks!

Posted

Hi, new comer! I'm a PHP newbie newer than you, but the following line looks suspect to me...

<input type="hidden" name="ID" value="<?php echo $currentRecord;?>">

At first I thought it was your call to $recordID = $_POST['ID']; since I didn't think ID was in the POST, but then I saw you had did have ID in the post but it didn't look right. I don't know FX but maybe it should be $CurrentRecID or $currentRecordID or something?

In CDML, I used to see that a lot w/folks... missing or malformed [FMP-CurrentRecID] statements which are needed for any edit. I could be way off, though, since I'm in the dark but that's my newbie guess!

--ST

Posted

Steve, I add one line to print $recordID, and output is correct. also, if the pointer points to a wrong record, the following statements should not work either.

$Query->AddDBParam('test', $_POST['test']);

$Query->AddDBParam('Injury_Date', $_POST['Injury_Date']);

But thank you very much for looking into my code. Really glad I'm not alone in dark!

Posted

Well, if no one else offers any good ideas... here are some more gooses you chase if you like...

- initialization of variables in functions

I think php changed the requirement for variables since FX was written; try pre-initializing variables in your functions before the functions try to use them. $myfield = ""; or using VAR.

- foreach

"PHP 4 (not PHP 3) includes a foreach construct, much like Perl and some other languages. This simply gives an easy way to iterate over arrays. foreach works only on arrays, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable..."

http://us4.php.net/foreach

- layout

I don't know if FX has layout references, but sometimes I'd refer to fields that were not on my web layout and no errors would be generated but data would be blank. If no layout was specified, FMP uses some kind of Layout.0 hidden layout that has all fields or something.

That's all I got... anyone else?

--ST

This topic is 7541 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.