This topic is locked

events - Before Edit Insert a record into another table

5/26/2011 3:17:47 PM
PHPRunner General questions
A
ashumak author

//** Insert a record into another table ****

global $conn;

$strSQLInsert = "insert into --rbegin--term_history--rend-- (TerminalID, Merchant_Name,MID_Number,terminal_type,Assigned_S_N,Swap_s_n,softwareversion,pinpad,Sim,assigned_date) values (TerminalID, Merchant_Name,MID_Number,terminal_type,Assigned_S_N,Swap_s_n,softwareversion,pinpad,Sim,assigned_date)";

db_exec($strSQLInsert,$conn);
Above is what I have. both tables are copies of each other. The end result is that it creates a blank record? HELP!
Alan

Sergey Kornilov admin 5/26/2011

Here is an example that can help you understand it better:

global $conn;

$strSQLInsert = "insert into term_history (TerminalID, Merchant_Name)

values (".$values["TerminalID"].", '".$values["Merchant_Name"]."')";

db_exec($strSQLInsert,$conn);



Note that text field need to be wrapped by single quotes in your query.

A
ashumak author 5/26/2011

OK, Changed it to Before Edit, Save new data in another table:
global $conn,$strTableName;
$strSQLSave = "INSERT INTO term_history (TerminalID, Merchant_Name, MID_Number, terminal_type, Assigned_S_N, Swap_s_n, softwareversion, pinpad, Sim, assigned_date) values (";
$strSQLSave .= $values["--rbegin--TerminalID--rend--"].",";

$strSQLSave .= $values["Merchant_Name"].",";

$strSQLSave .= $values["--rbegin--MID_Number--rend--"].",";

$strSQLSave .= $values["--rbegin--terminal_type--rend--"].",";

$strSQLSave .= $values["--rbegin--Assigned_S_N--rend--"].",";

$strSQLSave .= $values["--rbegin--Swap_s_n--rend--"].",";

$strSQLSave .= $values["--rbegin--Assigned_S_N--rend--"].",";

$strSQLSave .= $values["--rbegin--softwareversion--rend--"].",";

$strSQLSave .= $values["--rbegin--pinpad--rend--"].",";

$strSQLSave .= $values["--rbegin--Sim--rend--"].",";

$strSQLSave .= $values["--rbegin--softwareversion--rend--"].",";

$strSQLSave .= $values["assigned_date"];
$strSQLSave .= ")";

db_exec($strSQLSave,$conn);
Getting error:
Error type 256

Error description You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'i7910,37900810-25881996,37900810-25881987,37900810-25881996,6.04,30500820-938023' at line 1

URL portal.swiftpayment.ca/Terminal_Swaps_edit.php?

Error file /home/ashumak/portal/include/dbconnection.php

Error line 36

SQL query INSERT INTO term_history (TerminalID, Merchant_Name, MID_Number, terminal_type, Assigned_S_N, Swap_s_n, softwareversion, pinpad, Sim, assigned_date) values (32400000,SWIFTPAYMENT,,i7910,37900810-25881996,37900810-25881987,37900810-25881996,6.04,30500820-93802305,,6.04,2011-05-26)
Call stack

File: line Function Arguments

0. include/dbconnection.php:36 db_query 1. INSERT INTO term_history (TerminalID, Merchant_Name, MID_Number, terminal_type, Assigned_S_N, Swap_s_n, softwareversion, pinpad, Sim, assigned_date) values (32400000,SWIFTPAYMENT,,i7910,37900810-25881...;

  1. Resource id #11;

    1. include/dbconnection.php:47 db_exec 1. INSERT INTO term_history (TerminalID, Merchant_Name, MID_Number, terminal_type, Assigned_S_N, Swap_s_n, softwareversion, pinpad, Sim, assigned_date) values (32400000,SWIFTPAYMENT,,i7910,37900810-25881...;


  2. Resource id #11;

    2. include/Terminal_Swaps_events.php:180 eventclass_Terminal_Swaps->BeforeEdit 1. Array ( [TerminalID] => 32400000 [MID_number] => 3240000000 [Merchant_Name] => SWIFTPAYMENT [terminal_type] => i7910 [Assigned_S_N] => 37900810-25881996 [softwareversion] => 6....;


  3. TID_ID=1;
  4. Array ( [TID_ID] => 1 [TerminalID] => 32400000 [MID_number] => 3240000000 [Merchant_Name] => SWIFTPAYMENT [terminal_type] => i7910 [Assigned_S_N] => 37900810-25881996 [soft...;
  5. Array ( [TID_ID] => 1 ) ;
  6. ;
  7. ;

    3. Terminal_Swaps_edit.php:546 Global scope N/A


    Any suggestions on this?
    Alan



Sergey Kornilov admin 5/27/2011
  1. Remove all --rbegin-- and --rend--
  2. Make sure all text values are wrapped by single quotes. Take another look at my example.

A
ashumak author 5/27/2011


  1. Remove all --rbegin-- and --rend--
  2. Make sure all text values are wrapped by single quotes. Take another look at my example.


Hi,
Did all that and still the same result....

A
ashumak author 5/27/2011



Hi,
Did all that and still the same result....


Did that...

Have this,

global $conn;$strSQLInsert = "insert into term_history (TerminalID, MID_Number, Merchant_Name , terminal_type, Assigned_S_N, softwareversion, pinpad, Sim, assigned_date, last_edited_by, Swap_s_n) values (".$values["TerminalID"].", '".$values["MID_Number"].", '".$values["Merchant_Name"].", '".$values["terminal_type"].", '".$values["Assigned_S_N"].", '".$values["softwareversion"].",'".$values["pinpad"].",'".$values["Sim"].",'".$values["assigned_date"].", '".$values["last_edited_by"].", '".$values["Swap_s_n"]."')";db_exec($strSQLInsert,$conn);
Still error?

Suggestions?

L
Lena 5/30/2011

Hi,

there is a syntax error in your code: you've missed quotes in the SQL query. Please find updated code:

global $conn;

$strSQLInsert = "insert into term_history (TerminalID, MID_Number, Merchant_Name , terminal_type, Assigned_S_N, softwareversion, pinpad, Sim, assigned_date, last_edited_by, Swap_s_n)

values (".$values["TerminalID"].", '".$values["MID_Number"]."', '".$values["Merchant_Name"]."', '".$values["terminal_type"]."', '".$values["Assigned_S_N"]."', '".$values["softwareversion"]."','".$values["pinpad"]."','".$values["Sim"]."','".$values["assigned_date"]."', '".$values["last_edited_by"]."', '".$values["Swap_s_n"]."')";

db_exec($strSQLInsert,$conn);


Also to debug code we recommend to print executed query on the page:

echo $strSQLInsert;



Then run this SQL in the database (usign any MySQL administrative tool) and correct it if needed.

A
ashumak author 6/6/2011



Hi,

there is a syntax error in your code: you've missed quotes in the SQL query. Please find updated code:

global $conn;

$strSQLInsert = "insert into term_history (TerminalID, MID_Number, Merchant_Name , terminal_type, Assigned_S_N, softwareversion, pinpad, Sim, assigned_date, last_edited_by, Swap_s_n)

values (".$values["TerminalID"].", '".$values["MID_Number"]."', '".$values["Merchant_Name"]."', '".$values["terminal_type"]."', '".$values["Assigned_S_N"]."', '".$values["softwareversion"]."','".$values["pinpad"]."','".$values["Sim"]."','".$values["assigned_date"]."', '".$values["last_edited_by"]."', '".$values["Swap_s_n"]."')";

db_exec($strSQLInsert,$conn);


Also to debug code we recommend to print executed query on the page:

echo $strSQLInsert;



Then run this SQL in the database (usign any MySQL administrative tool) and correct it if needed.


Argh...had it right, now must have made another mistake...
global $conn;

$strSQLInsert = "insert into term_history (TerminalID, MID_Number, Merchant_Name , terminal_type, Assigned_S_N, softwareversion, pinpad, Sim, assigned_date, last_edited_by, Swap_s_n, Swap_pinpad, Swap_SIM) values (".$values["TerminalID"].", '".$values["MID_Number"]."', '".$values["Merchant_Name"]."', '".$values["terminal_type"]."', '".$values["Assigned_S_N"]."', '".$values["softwareversion"]."','".$values["pinpad"]."','".$values["Sim"]."','".$values["assigned_date"]."', '".$values["last_edited_by"]."', '".$values["Swap_s_n"]."', '".$values["Swap_pinpad"]."', '".$values["Swap_SIM"]."')"; db_exec($strSQLInsert,$conn);// Use "Add Action" button to add code snippets.

Sergey Kornilov admin 6/6/2011

Without seeing database structure and the actual error message finding what is wrong would not be easy.
If you have a valid support contract post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program.