PHP Classes

Insert

Recommend this page to a friend!

      Auto Insert  >  All threads  >  Insert  >  (Un) Subscribe thread alerts  
Subject:Insert
Summary:Insert value from query
Messages:4
Author:Jose Gomes
Date:2008-08-01 11:47:07
Update:2008-08-17 15:31:33
 

  1. Insert   Reply   Report abuse  
Picture of Jose Gomes Jose Gomes - 2008-08-01 11:47:07
Sorry, I'm new and the greenest possible

form addnewrecord
function beforeupdate

global $conn;
$strSQLExists = "select * from price_list where codigo='".$values["Code"]."'";
$rsExists = db_query($strSQLExists,$conn);
$data=db_fetch_array($rsExists);
if($data)
{
// if record exists send 2 values from query completing the fields and inform success

$strSQLInsert= ("insert _orders (Description, Price) VALUES ('".$data["Item"]."', '".$data["Unit_price"]."')");
db_exec($strSQLInsert,$conn);

$message="Updated ".$data["Item"].$data["Unit_price"];

foreach($values as $field=>$value)
$message.= $field." : ".$value."\r\n";
}
else
{
// if dont exist do something else

$message="There is No ";


foreach($values as $field=>$value)
$message.= $field." : ".$value."\r\n";


}

return true;

Problem, instead of

id¦code¦description¦quantity¦price
xx!0012!ipsum alori¦00000010¦£10.00

id¦code¦description¦quantity¦price
00!0000!ipsum alori¦00000000¦£10.00
xx!0012! ¦00000010¦£00.00

Stoopid hey?

  2. Re: Insert   Reply   Report abuse  
Picture of William Lang William Lang - 2008-08-01 13:08:02 - In reply to message 1 from Jose Gomes
You'll wanna use the UPDATE command instead of INSERT when updating rows.

  3. Re: Insert   Reply   Report abuse  
Picture of Jose Gomes Jose Gomes - 2008-08-01 13:49:26 - In reply to message 1 from Jose Gomes
It seems to me that update command needs a different approach. I think I would have to go round the strategy.
I wanted to close the addnew form with two more values to complete the record update.
But I am happy to use the update command, only I cannot think how.

Thank you

  4. Re: Insert   Reply   Report abuse  
Picture of Jose Gomes Jose Gomes - 2008-08-17 15:31:33 - In reply to message 3 from Jose Gomes
Here is

$strSQLInsert= ("UPDATE _orders SET Description='".$data["Item"]."', Price='".$data["Unit_price"]."' where code='".$data["Code"]."'");
db_exec($strSQLInsert,$conn);

It only updates the record in an afterUpdate Event

In beforeUpdate it doesn't work