This topic is locked

$where

7/31/2006 3:13:21 PM
PHPRunner General questions
A
amirgulamali author

can somebody pls help..
I am inserting a record into another table using

function BeforeEdit(&$values, $where)

{
// Parameters:

// $values - Array object.

// Each field on the Edit form represented as 'Field name'-'Field value' pair

// $where - string with WHERE clause pointing to record to be edited
//********** Insert a record into another table ************
global $conn;
$strSQLInsert = "insert into _students (Completed) values ('1ee0') where ($fname = $values["fname"])";
db_exec($strSQLInsert,$conn);
return true;
// return true if you like to proceed with editing this record

// return false in other case
}


but I am running into error. i suspect its my where clause...

any ideas?

adamdidthis 7/31/2006

try

$strSQLInsert = "insert into _students (Completed) values ('1ee0') where fname='".$values["fname"]."'";
A
amirgulamali author 7/31/2006

im still getting an error:
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 'where fname=''john''' at line 1
does the where condition need to use a PK field?

A
amirgulamali author 7/31/2006

Let me rephrase my question since no one replied, i guess i was not clear.
I have 3 tables:

_students

_1ee0

_2ee0
-- ----------------------------

-- Table structure for _1ee0

-- ----------------------------

CREATE TABLE `_1ee0` (

`id` int(11) NOT NULL auto_increment,

`fname` varchar(50) default NULL,

`lname` varchar(50) default NULL,

`student_no` int(11) default NULL,

`email` varchar(50) default NULL,

`comments` varchar(50) default NULL,

`course` varchar(50) default NULL,

`course status` varchar(50) default NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- ----------------------------

-- Table structure for _2ee0

-- ----------------------------

CREATE TABLE `_2ee0` (

`id` int(11) NOT NULL auto_increment,

`fname` varchar(50) default NULL,

`lname` varchar(50) default NULL,

`student_no` int(11) default NULL,

`email` varchar(50) default NULL,

`comments` varchar(50) default NULL,

`course` varchar(50) default NULL,

`course status` varchar(50) default NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- ----------------------------

-- Table structure for _students

-- ----------------------------

CREATE TABLE `_students` (

`id` int(11) NOT NULL auto_increment,

`fname` varchar(50) default NULL,

`lname` varchar(50) default NULL,

`student_no` int(11) default NULL,

`course` varchar(50) default NULL,

`email` varchar(50) default NULL,

`Completed` varchar(50) default NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;
I want to insert hardcoded values into _students(in its field called completed) when the value of the fields course status in either _1ee0 or _2ee0 tables is Completed.
I tired using events as follows:

function BeforeEdit(&$values, $where)

{
// Parameters:

// $values - Array object.

// Each field on the Edit form represented as 'Field name'-'Field value' pair

// $where - string with WHERE clause pointing to record to be edited
//********** Insert a record into another table ************
global $conn;
$strSQLInsert = "insert into _students (Completed) values('1ee0');
db_exec($strSQLInsert,$conn);
return true;
// return true if you like to proceed with editing this record

// return false in other case
}


This works but it inserts '1ee0' in _students as a new record (in a new row).. I want to insert the value in the row corresponding to the entry which is being edited in _1ee0 (i have uniq identifiers for each recors)
When I add where _students.id =1"; to the insert statement, I get errors (Syntax error). What am I missing? I want to add the hardcoded values in another table with matching field values

(for instance "id" in _students and "id" in _1ee0 match)
Hope my question is clear, Please help.
Thanks in advance

J
Jane 8/1/2006

Amir,
try to use following code for the _1ee0 table:

function BeforeEdit(&$values, $where)

{

global $conn;
if ($values["coursestatus"]=="'completed'")

{

$strSQLInsert = "update `_students` set `Completed`='1ee0' where `_students`.`student_no` = ".$values["student_no"];
db_exec($strSQLInsert,$conn);

}

return true;
}
A
amirgulamali author 8/1/2006

Hellow,
I added that code in my _1ee0_events.php but now it doesnt add anything to _students even if the course status == Completed

A
amirgulamali author 8/1/2006

It worked, thanks to you Jane! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=10154&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />