This topic is locked

Before Record Added Event Not Working!!

5/2/2009 6:01:46 AM
PHPRunner General questions
C
chinwag author

Hello, I am new to phprunner and am using the trial version. I am trying to let my potential users choose how many times a record is added to my database using a drop down select box which has a field name of 'HOW MANY'.
It isn't working and only adds the record once, The first field 'RECORD' is an autoincrement INT field if this makes a difference.
heres my code which I suppose may be wrong:

<?php
// Before record added

function BeforeAdd(&$values,&$message,$inline)

{

// Parameters:

// $values - Array object.

// Each field on the Add form is represented as a 'Field name'-'Field value' pair
//********** Custom code ************

// put your custom code here
for($i=1;$i<=$values["HOW_MANY"];$i++)

{

mysql_query("Insert into INVENTORY ('RECORD','SITE','DISCIPLINE','ITEM TYPE','BATCH/LOT NUMBER','EXPIRY DATE','HOW MANY','RECEIVED BY','RECEIVED ON','PACKAGE INSERT CHECKED','USE COMMENCED BY','USE COMMENCED ON','TRANSFERRED BY','TRANSFERRED TO','SECOND SITE RECEIVED BY','NOTE/COMMENTS') VALUES ('".$i."','".$values["SITE"]."','".$values["DISCIPLINE"]."','".$values["ITEM_TYPE"]."','".$values["BATCH/LOT_NUMBER"]."','".$values["EXPIRY_DATE"]."','".$values["HOW_MANY"]."','".$values["RECEIVED_BY"]."','".$values["RECEIVED_ON"]."','".$values["PACKAGE_INSERT_CHECKED"]."','".$values["USE_COMMENCED_BY"]."','".$values["USE_COMMENCED_ON"]."','".$values["TRANSFERRED_BY"]."','".$values["TRANSFERRED_TO"]."','".$values["SECOND_SITE_RECEIVED_BY"]."','".$values["NOTE/COMMENTS"]."')");

}
return true;
// return true if you like to proceed with adding new record

// return false otherwise
} // function BeforeAdd
?>
D
danaci 5/2/2009

$global conn;

$sql = "Your SQL query here";

db_exec($sql,$conn);

C
chinwag author 5/3/2009

$global conn;

$sql = "Your SQL query here";

db_exec($sql,$conn);


Hi
Thanks for your reply, but this doesnt work. I need to be able to add the record the number of times the user states in the HOW MANY field.

Sergey Kornilov admin 5/3/2009

Try this:

function BeforeAdd(&$values,&$message,$inline)

{

// Parameters:

// $values - Array object.

// Each field on the Add form is represented as a 'Field name'-'Field value' pair
$global conn;
for($i=1;$i<=$values["HOW_MANY"];$i++)

{

$sql = "Insert into INVENTORY ('RECORD','SITE','DISCIPLINE','ITEM TYPE','BATCH/LOT NUMBER','EXPIRY DATE','HOW MANY','RECEIVED BY','RECEIVED ON','PACKAGE INSERT CHECKED','USE COMMENCED BY','USE COMMENCED ON','TRANSFERRED BY','TRANSFERRED TO','SECOND SITE RECEIVED BY','NOTE/COMMENTS') VALUES ('".$i."','".$values["SITE"]."','".$values["DISCIPLINE"]."','".$values["ITEM_TYPE"]."','".$values["BATCH/LOT_NUMBER"]."','".$values["EXPIRY_DATE"]."','".$values["HOW_MANY"]."','".$values["RECEIVED_BY"]."','".$values["RECEIVED_ON"]."','".$values["PACKAGE_INSERT_CHECKED"]."','".$values["USE_COMMENCED_BY"]."','".$values["USE_COMMENCED_ON"]."','".$values["TRANSFERRED_BY"]."','".$values["TRANSFERRED_TO"]."','".$values["SECOND_SITE_RECEIVED_BY"]."','".$values["NOTE/COMMENTS"]."')";

db_exec($sql,$conn);

}
return true;
// return true if you like to proceed with adding new record

// return false otherwise
} // function BeforeAdd
C
chinwag author 5/4/2009

I get the error below with your code:

Parse error: syntax error, unexpected T_STRING in /home/content/../../../.././INVENTORY_events.php on line 19
J
Jane 5/4/2009

Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.

C
chinwag author 5/4/2009

uploaded.