This topic is locked

Insert Multiply Entries in a table When Clicking A Button

2/25/2008 9:13:24 AM
PHPRunner General questions
C
ckapote author

Hi ,
I have a table with name tblinventory containing following fields :

idi - (Autonumber Primary)

code - (Varchar)

description - (Varchar)

Unit - (Varchar)

quantity - (Varchar)

ROB - (Varchar)

Category - (Varchar)
I have another one table with name tblrequisition containing

the same fields with the above table .

What I need that in the add page of tblrequisition to add a button

named 'Insert Provisions List' and when clicking on that button

to insert all values from tblinventory into tblrequisition with category='provisions'.
PLs Help!

J
Jane 2/26/2008

Hi,
you can do it using custom event on the Visual Editor tab (Insert PHP code snippet option).

Here is a sample:

$str = "<input type=button class=button value=insert onclick=\"windiw.location='tablename_edit.php?editid1=".$_REQUEST["editid1"]."&insert=yes'\">";


Then check $_REQUEST["insert"] variable in the Edit page: Before process event and execute your query.

C
ckapote author 2/26/2008

Hi,

you can do it using custom event on the Visual Editor tab (Insert PHP code snippet option).

Here is a sample:
Then check $_REQUEST["insert"] variable in the Edit page: Before process event and execute your query.



Thanks one again , but iam not familiar how to write and execute the query . can you Help ? please

J
Jane 2/27/2008

Hi,
here is a sample:

global $conn;

if ($_REQUEST["insert"]=="yes")

{

$strInsert = "insert into TableName (FieldName1,FieldName2) values (Value1,Value2)";

db_exec($strInsert,$conn);

}



Replace TableName, FieldName1, FieldName2 with your actual names, Value1 and Value2 with your actual values.

C
ckapote author 2/27/2008



Thanks one again , but iam not familiar how to write and execute the query . can you Help ? please



Thanks very helpful , but I need to insert certain values not all the available values , for example to insert these values from table1 where the field category is equal to "provisions" and furthermore for the specific logged in user .

Can you help ?

J
Jane 2/27/2008

Hi,
to select all records from table1 use this code:

global $conn;

$str = "select * from table1 where category='provisions' and username='".$_SESSION["UserID"]."'";

$rs = db_query($rs,$conn);

$data = db_fetch_array($rs);

//$data["fieldname1"] - value of fieldname1 field

//$data["fieldname2"] - value of fieldname2 field



where category and username are your actual field names.

C
ckapote author 2/27/2008

Hi,

to select all records from table1 use this code:
where category and username are your actual field names.


and then I have to import the insert code provided with your previous post ?