This topic is locked

multiple queries

7/17/2007 7:06:43 AM
PHPRunner General questions
M
morpheus author

I'm using phprunner 4,
I have a two tables, locations and items, when I add details for a new item (or update and existing item) i select a user from a pulldown on the items table, what I want to do is query a "status" field in the users table and set the status in the items table automaticaly,
locations table
shelf1 available

shelf2 available

shelf3 available

repair unavailable

scrapped unavailable
items table

item, description, location, status, currentrecord
The thing I need to do is when a location is updated it needs to update the status according to the location table.
can i have two queries in an "after add" action because I'm already setting the currentrecord field to true (if it's an old record I've usede "copy" on I'm setting the value to false on the old record too this gives me an audit trail of all parts in stores.
regards
Morpheus

M
morpheus author 7/17/2007

After my last post I tried this in after add and got an error
global $conn;

$str2 = "select LAST_INSERT_ID() from `items`";

$rs2 = db_query($str2,$conn);

$data2 = db_fetch_numarray($rs2);

$_SESSION["last_inserted_row"] = $data2[0];
//code to get the location selected from the last inserted record

$str6 = "select location from items where uniqueid = $_SESSION["last_inserted_row"]";

$rs6 = db_query($str6,$conn);


//code to lookup the default status for the location selected above


$str3 = "select defstatus from adminstatus where location = $rs6";

$rs3 = db_query($str3,$conn);
//code to update the status of the last added record with the status obtained from the adminstatus table

$str4 = "update set status = $rs3 where uniqueid =$_SESSION["last_inserted_row"]";

$rs4 db_query($str4,$conn);
//code to display the details of the added record

header("Location: items_view.php?editid1=".$_SESSION["last_inserted_row"]);

$strSQLInsert = 'INSERT INTO `stockcontrol`.`_iteminc` (`value`, `CreatedByPHPRunner`, `dummy`) VALUES (NULL, NULL, \'bob\');';

db_exec($strSQLInsert,$conn);

return true;
I then get the error message
Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/stores/include/WasteManager_events.php on line 115
Any suggestions as to what I'm doing wrong?

J
Jane 7/17/2007

Hi,
to debug your code I recommend you to use echo expression after all your queries:

global $conn;

$str2 = "select LAST_INSERT_ID() from `items`";

$rs2 = db_query($str2,$conn);

$data2 = db_fetch_numarray($rs2);

$_SESSION["last_inserted_row"]= $data2[0];
//code to get the location selected from the last inserted record

$str6 = "select location from items where uniqueid = $_SESSION["last_inserted_row"]";

echo $str6;

$rs6 = db_query($str6,$conn);
//code to lookup the default status for the location selected above

$str3 = "select defstatus from adminstatus where location = $rs6";

echo $str3;

$rs3 = db_query($str3,$conn);
//code to update the status of the last added record with the status obtained from the adminstatus table

$str4 = "update set status = $rs3 where uniqueid =$_SESSION["last_inserted_row"]";

echo $str4;

$rs4 db_query($str4,$conn);

...