This topic is locked

Add data to another table from custom code

9/9/2009 3:45:32 PM
PHPRunner General questions
L
luck author

Hi,
I have 2 table : Product and Cart.

In Product table I have 4 fields: ID, Name, Price and another ID with alias BUY(that should be a button).

In Cart table I have 3 fields: ID, Product, Price.

I need to add a custom code for BUY (View as Custom) in visual editor to add Name and Price from the product to Cart table ( Product and Price fields) and redirect to Cart_list.
I tried these codes:
global $conn;

$strSQLInsert = "insert into _cart (Product, Price) values (".$data["Product"].", ".$data["Price"].")";

db_exec($strSQLInsert,$conn);

$value = "<a href=\"Cart_list.php\"><IMG src=images/Cart.png></a>";
and
global $conn;

$strSQLInsert = "insert into _cart (Product, Price) values (".$_SESSION["Product"].", ".$_SESSION["Price"].")";

db_exec($strSQLInsert,$conn);

$value = "<a href=\"Cart_list.php\"><IMG src=images/Cart.png></a>";
but without the desired result.
Please help me with the correct code for what I need to do.
Thank you in advance !

Sergey Kornilov admin 9/9/2009

'View as' Custom is a wrong place to put this kind of script. Code needs to be moved to BeforeProcess event.
I recommend to check tutorial at http://www.xlinesoft.com/phprunner/docs/email_selected_records.htm that explains how to add a button and execute PHP code after button was clicked.