access own formdata in form submit

Status
Not open for further replies.

Mikmac

New Member
Maybe you can help me with this script for F1.0.6.

It is a form submit script that creates a serie of new records.
What it does briefly:
1 it retrieves records from another table (table_13)
2 for each record that is retrieved it creates a new record in 'this' table (table 19)
3 it should copy data from table 13 and from 'this' form into the newly created records in table 19.

Code:
$sql="SELECT * FROM jos_fabrik_formdata_13 WHERE status='approved'";
$csresult=mysql_query($sql);
$num=mysql_num_rows($csresult);

mysql_close();

$i=0;
while ($i < $num) {

$field1=mysql_result($csresult,$i,"bwof_buildingid");
$id=mysql_result($csresult,$i,"fabrik_internal_id");
[color=blue]$month = $aData['jos_fabrik_formdata_19___check_month'];[/color]

$sql="INSERT INTO jos_fabrik_formdata_19 (check_buildingid, cs_join, month) VALUES ('$field1', '$id', [color=blue]'$month'[/color])";
$database->setQuery($sql);
$database->query();

$i++;
}

This basicly works apart from the indicated in blue: "check_month" is one of the few fields that is in the form from where this script is submitted. So if that field says "10" I want to have that value in all the newly created records (in the "month" field.

It does not recognise $aData['jos_fabrik_formdata_19___check_month']. Do you know why? I also tried to place it outside the 'while'-loop area, but then it is not being recognised either. It should be fairly simple to grab the data from the submitted form, but can't put my finger on it this time.
 
var_dump() is your friend. Try ...

var_dump($aData);

... just before you access that field, and see what $aData actually contains at that point.

-- hugh
 
Sounds good, but I still don't get it.
Do you mean to put the var_dump just before the the query? Like:

...
var_dump($aData);
$sql="INSERT INTO jos_fabrik_formdata_19 (check_buildingid, cs_join, month) VALUES ('$field1', '$id', '$month')";

But what if I have more than 1 field to use.

or put it in a new variable? Like:
$check_month = $aData('jos_fabrik_formdata_19___check_month');
$month=var_dump($check_month);

Both give errors ("function name must be a string)
But still wondering why would in the above example $check_month not hold the data?
 
var_dump will print the data contained within the array $aData, what Hugh is suggesting is that you do that so that you can see what the keys are in $aData so you can then use them to grab the correct information.

Personally I prefer this:

Code:
echo "<pre>":print_r($aData);echo "</pre>";
exit;

print_r gives you just the info you need and no more, and the exit; will stop your script so you can see what print_r outputs.

or put it in a new variable? Like:
$check_month = $aData('jos_fabrik_formdata_19___check_month');

yikes thats going to give you all sorts of errors when acccessing an array of data you need to use square brackets, e.g.

Code:
$check_month = $aData['jos_fabrik_formdata_19___check_month'];
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top