This topic is locked

Insert Data Button on View Page

9/4/2008 6:33:37 AM
PHPRunner General questions
F
fawad112 author

Hi,
I need some help in adding a button on view page. This button will insert or update a couple of fields in the 2 table.(Like the field from the view(main table) to the accounts table and the userid from the accounts table to the main table) Is it possible ? I want to add this button just after "back to list" i am new to php and mysql so a code for buttong and the event will be greatly apprecaited. I tried using some queries but i think i am missing some thing.
Thanks

J
Jane 9/4/2008

Hi,
to create button edit your view page in HTML mode on the Visual Editor tab.

Here is a sample:

<input class=button type=button value=Update onclick="window.location.href='tablename_view.php?editid1={$show_key1}&update=yes';">


Then check $_REQUEST["update"] in the View page: Before process event on the Events tab and update second table.

Here is a sample:

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

{

//update secodn table here

}

F
fawad112 author 9/4/2008

Hi, thanks for the help ... i having some problem again ..
[codebox]

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

{

global $conn;

$strUpdate = "update termpaper set writerid=".$values["writerid"]." WHERE ref=".$values["ref"];

db_exec($strUpdate,$conn);

}

[/codebox]
i m using this to update the table termpaper. termpaper has a field writerid which is empty and the table accounts also have the field "writerid" where it has some value. I want to set the value from accounts>writerid to termpaper>writerid once the user click update button on the view page.
Do i have to use select statement first to get the date from accounts table and then update it on the termpaper table ?
i was also trying to update the table with the hard coded values but it is not working ..
[codebox]if ($_REQUEST["update"]=="yes")

{

global $conn;

$strUpdate = "update termpaper set writerid='WIK' WHERE ref='ref'";

db_exec($strUpdate,$conn);

}[/codebox]
ref is the primary key of the table termpaper and WIK is writerid which i want to get from the accounts table.

J
Jane 9/5/2008

Hi,
yes, you need to select values from accounts table first.
Regarding the second code snippet.

Please make sure this query works in the database directly.

F
fawad112 author 9/5/2008

Hi jane
thanks for the reply. How do i pick the value of the ref. the value of this field is shown in VIEW.
[codebox]if ($_REQUEST["update"]=="yes")

{

global $conn;

$strUpdate = "update termpaper set writerid='WIK' WHERE ref=$ref";

db_exec($strUpdate,$conn);

}[/codebox]
And can you please give some example for the select and update statement. I know i may be irritating you but i m stuck and i not good at this <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=32717&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />
Thanks

J
Jane 9/5/2008

Hi,
to select values from database on the view page use following code as sample:

global $conn;

if (@$_REQUEST["editid1"])

{

$str = "select Field1, Field2 from TableName where RecordID=".$_REQUEST["editid1"];

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

$data = db_fetch_array($rs);

$ref = $data["Field1"];

}