This topic is locked

Insert a record into another table

12/5/2008 6:40:54 AM
PHPRunner General questions
M
mauro author

After record deleted --> Insert a record into another table
i 've 1 databse with 2 table (tableA e tableB)
in tableA field are
pippo, pluto, paperino
//** Insert a record into another table ****

global $conn;

$strSQLInsert = "insert into tableB (pippo, pluto, paperino) values (Value1, Value2, Value3)";

db_exec($strSQLInsert,$conn);
but 'ive an error

J
Jane 12/5/2008

Mauro,
you should replace all Value1, Value2 and Value3 with your actual one.

All entered values are in the $values array, I.e. $values["pippo"], $values["pluto"], etc.

Add single quotes around text and date values in your SQL query.

Here is a sample:

$strSQLInsert = "insert into TableName (NumberField, DateField, TextField) values (".$values["NumberField"].", '".$values["DateField"]."', '".$values["TextField"]."')";

M
mauro author 12/5/2008
function AfterDelete($where,&$deleted_values)

{
// Parameters:

// $deleted_values - Array object.

// Each field on the List page is represented as a 'Field name'-'Field value' pair

// $where - string with WHERE clause pointing to record to be deleted.
// ********** Send simple email ************
$email="my@email.com";

$message="My Message";

$subject="Subjetc;
mail($email, $subject, $message);
//********** Insert a record into another table ************

global $conn;

$strSQLInsert = "insert into tableB (name, surname , number, mail, date, note, id) values ('".$values["name"]."', '".$values["surname"]."', ".$values["number"].", '".$values["mail"]."', '".$values["date"]."', '".$values["note"]."')";

db_exec($strSQLInsert,$conn);


text and date values: name, surname, date, note

number value: number

Id value (number) is autoincrement (it's not visible in add\view page)
bit i've this error:

Error Type 8

Undefined variable: values

J
Jane 12/5/2008

Hi,
if you use BeforeDelete event replace all $values with $deleted_values in your code.