This topic is locked

SAVE NEW DATA INTO ANOTHER TABLE

6/23/2008 7:55:09 AM
PHPRunner General questions
M
marpunta author

I am not much of a programmer so i rely heavily on the sollutions that PHPR gives me

SO this is what i am doing

I want when i add a record in table "tamio" some of the fields to be added in table "litourg"

I used a before record added event like this
//** Save new data in another table ****

global $conn,$strTableName;
$strSQLSave = "INSERT INTO litourg (littype, litinfo) values (";
$strSQLSave .= $values['tamtype'].",";

$strSQLSave .= $values['taminfo'];
$strSQLSave .= ")";

db_exec($strSQLSave,$conn);
return true;
// return true if you like to proceed with adding new record

// return false otherwise
litourg littype and litinfo are the other table and fields

and tamtype , taminfo are the fields from tamio that i want to be copied to litourg
BUT

when i add a record it gives me an error except when the values of tamtype and taminfo are numbers
Specificly the error that i get is this
Λάθος τύπος 256

Λάθος περιγραφής Unknown column 'test' in 'field list'

URL localhost/tam_test/tamio_add.php?

Λάθος αρχείο W:\www\tam_test\include\dbconnection.php

Λάθος γραμμή 26

SQL Ερώτημα insert into `tamio`
WHAT AM I DOING WRONG??
thanx

Sergey Kornilov admin 6/23/2008

Make sure you add single quotes around text values i.e.

global $conn,$strTableName;

$strSQLSave = "INSERT INTO litourg (littype, litinfo) values (";
$strSQLSave .= $values['tamtype'].",";

$strSQLSave .= "'" . $values['taminfo'] . "'";
$strSQLSave .= ")";

db_exec($strSQLSave,$conn);

M
marpunta author 6/24/2008

Thank you

It worked smoothly
Now i am trying something with if statement

but i know where to turn if it gets difficult
Thanx again <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=30545&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />