function displayDeleteForm(){
//get $fields into the function namespace
global $fields;
global $conn;
/* Create and execute query. */
// Loop through each row, outputting the actype and name
echo <<
Pilots Logbook entries stored in Oracle Relational Database
under Redhat Fedora 8 Linux
HTML;
} //close function
// ............................................................ ..... function deleteRecords()
//
function insertRecord()
{
global $rowInsert;
$db = "(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = LMKIIIGDNSID)
)
)";
if ($conn=oci_connect('landon', 'rumprocella',$db))
{
echo "Successfully connected to Oracle.\n";
}
else
{
$err = OCIError();
echo "Oracle Connect Error " . $err['message'];
}
// Retrieve the posted log book information.
global $fields;
//add some very crude validation
foreach ($fields as $field){
if (empty($_POST[$field])){
$messages[] = "You must complete the field $field \r\n";
} else {
$dFields[$field] = mysql_real_escape_string(trim($_POST[$field]));
}
}
if (count($messages)>0) {
displayEntryForm($messages, $dFields);
exit();
}
//end validation
//get variables into the namespace
extract($dFields);
// Insert the log book information into the log book table
print("insertRecord".$rowInsert);
if($rowInsert)
{
$query = "UPDATE log_book_id set fdate = '$fdate', actype='$actype', acid='$acid', nlandings='$nlandings', nhours='$nhours' where log_id='$rowInsert'";
}
else
{
$query = "INSERT INTO log_book_id (log_id , fdate, actype, acid, nlandings, nhours) values (logid.nextval,'$fdate','$actype','$acid','$nlandings','$nho urs')";
}
global $fields;
global $dFields;
global $rowInsert;
// Loop through each log_book_id with an enabled checkbox
if (!isset($_POST['checkbox'])){
return true;
}
//else
foreach($_POST['checkbox'] as $key=>$val){
$toDelete[] = $key;
}
// errors
//get log_book_id table information
$user = "select * from log_book_id where log_id = $toDelete[0]";
$result = oci_parse($conn, $user);
$r = oci_execute($result);
//display log_book_id information
$count = 0;
$newArray = oci_fetch_assoc($result);
if ($count == 0) print_r($newArray);
$count = 1;
foreach ($fields as $field){
$fieldx = strtoupper($field);
${$field} = $newArray[$fieldx];
$dFields[$field] = ${$field};
}
$rowID = $newArray['LOG_ID'];
$rowInsert = $rowID;
print_r($dFields);
print ($rowInsert);
//note that we do not rely on the checkbox value as not all browsers submit it
//instead we rely on the name of the checkbox.
// insert the row information in the entry form
global $fields;
//end validation
displayEntryForm();
}
//.......................................................... .................function displayEntryForm()
function displayEntryForm($errorMessages=null, $dFields=null){
if (!empty($errorMessages)){
echo "
".explode('
', $errorMessages) . "
";
}
global $dFields;
//sort out field values
global $fields;
foreach ($fields as $field){
if (isset($dFields[$field])){
${$field} = $dFields[$field];
} else {
${$field} = '';
}
}
echo <<
HTML;
} //end display function
?>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: global not solving my problem
am 30.11.2008 20:24:28 von Micah Gersten
Fred Silsbee wrote:
> problem:
>
> I have resolved all problems in the PHP program below except one.
>
> Yes I know the program is in a mess but I will clean it up.
>
> This is a learning exercise!
>
> Basically there is one function per page.
>
> When I make a selection on a page, a function is executed.
>
> I need to pass the value of $rowInsert from one page to another.
>
> $rowInsert is altered when I enter the program (at the top).
>
> To verify the program works (outside this problem), I set the value = 525.
>
> Global does not persist the value between pages(functions).
>
> I can't use _POST because the value of $rowInsert is not associated with an entry slot(edit control).
>
> I could make an entry slot(edit control) just for this purpose but that is not good!
>
>
>
>
>
>
>
>
> /*
> drop sequence log_id;
> create sequence log_id
> increment by 1
> start with 1;
>
> drop table log_book_id;
>
> create table log_book_id ( log_id number primary key, fdate date, actype varchar2(16), acid varchar(16), nlandings number, nhoursnumber);
>
> insert into log_book_id values (logid.nextval, TO_DATE('08/12/1973','MM/dd/YYYY'),'C150','N5787G',1,1.8);
>
> insert into log_book_id values (logid.nextval, TO_DATE('08/17/1973','MM/dd/YYYY'),'C150','N5787G',3,1.5);
>
> insert into log_book_id values (logid.nextval, TO_DATE('08/26/1973','MM/dd/YYYY'),'C150','N5787G',10,1.8);
>
> insert into log_book_id values (logid.nextval, TO_DATE('09/01/1973','MM/dd/YYYY'),'C150','N5293S',9,1.7);
> */
> print("........................................ENTER........ ........");
> $rowInsert = 525; // temporary
> $db = "(DESCRIPTION =
> (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
> (CONNECT_DATA =
> (SERVER = DEDICATED)
> (SID = LMKIIIGDNSID)
> )
> )";
> if ($conn=oci_connect('landon', 'rumprocella',$db))
> {
> echo "Successfully connected to Oracle.\n";
> }
> else
> {
> $err = OCIError();
> echo "Oracle Connect Error " . $err['message'];
> }
>
> //construct a global variable for the form profile
> $fields = array("fdate", "actype", "acid", "nlandings", "nhours");
> ///
>
> // If the submit button has been pressed
> if (isset($_POST['select'])){
> displayDeleteForm();
> }elseif(isset($_POST['delete'])){
> deleteRecords();
> } elseif(isset($_POST['insert'])){
> insertRecord();
> } elseif (isset($_POST['new'])){
> displayEntryForm();
> } elseif (isset($_POST['update'])){
> showRecord();
> } else {
> //default action
> displayEntryForm();
> }
>
> //.......................................................... .................function displayDeleteForm()
>
> function displayDeleteForm(){
> //get $fields into the function namespace
> global $fields;
> global $conn;
> /* Create and execute query. */
> // Loop through each row, outputting the actype and name
> echo <<
> Pilots Logbook entries stored in Oracle Relational Database
> under Redhat Fedora 8 Linux
>
>
>
>
>
>
>
>
>
>
>
>
> HTML;
> } //close function
>
>
> // ............................................................ ..... function deleteRecords()
> //
>
> function deleteRecords()
> {
>
> $db = "(DESCRIPTION =
> (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
> (CONNECT_DATA =
> (SERVER = DEDICATED)
> (SID = LMKIIIGDNSID)
> )
> )";
>
> // Loop through each log_book_id with an enabled checkbox
> if (!isset($_POST['checkbox'])){
> return true;
> }
> //else
>
> foreach($_POST['checkbox'] as $key=>$val){
> $toDelete[] = $key;
> }
> //expand the array for an IN query
> $where = implode(',', $toDelete);
>
> if ($conn=oci_connect('landon', 'rumprocella',$db))
> {
> echo "Successfully connected to Oracle D.\n";
> }
> else
> {
> $err = OCIError();
> echo "Oracle Connect Error " . $err['message'];
> }
>
> $query = "DELETE FROM log_book_id WHERE log_id IN ($where)";
> echo($query);
> $result = oci_parse($conn, $query);
> $r = oci_execute($result);
> // Commit transaction
> $committed = oci_commit($conn);
> // Test whether commit was successful. If error occurred, return error message
> if (!$committed) {
> $error = oci_error($conn);
> echo 'Commit failed. Oracle reports: ' . $error['message'];
> }
> // Should have one affected row
> if ((oci_num_rows($result)== 0) ) {
> echo "
There was a problem deleting some of the selected items.
".oci_error().'
';
> // exit();
> } else {
> echo "
The selected items were successfully deleted.
";
> }
> //direct the user back to the delete form
> displayDeleteForm();
> } //end function
>
> //.......................................................... .................function insertRecord()
>
> function insertRecord()
> {
> global $rowInsert;
> $db = "(DESCRIPTION =
> (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
> (CONNECT_DATA =
> (SERVER = DEDICATED)
> (SID = LMKIIIGDNSID)
> )
> )";
> if ($conn=oci_connect('landon', 'rumprocella',$db))
> {
> echo "Successfully connected to Oracle.\n";
> }
> else
> {
> $err = OCIError();
> echo "Oracle Connect Error " . $err['message'];
> }
> // Retrieve the posted log book information.
> global $fields;
> //add some very crude validation
> foreach ($fields as $field){
> if (empty($_POST[$field])){
> $messages[] = "You must complete the field $field \r\n";
> } else {
> $dFields[$field] = mysql_real_escape_string(trim($_POST[$field]));
> }
> }
> if (count($messages)>0) {
> displayEntryForm($messages, $dFields);
> exit();
> }
> //end validation
>
> //get variables into the namespace
> extract($dFields);
> // Insert the log book information into the log book table
> print("insertRecord".$rowInsert);
> if($rowInsert)
> {
> $query = "UPDATE log_book_id set fdate = '$fdate', actype='$actype', acid='$acid', nlandings='$nlandings', nhours='$nhours' where log_id='$rowInsert'";
> }
> else
> {
> $query = "INSERT INTO log_book_id (log_id , fdate, actype, acid, nlandings, nhours) values (logid.nextval,'$fdate','$actype','$acid','$nlandings','$nho urs')";
> }
>
> $rowInsert = 0;
> // echo ($query);
> $result = oci_parse($conn, $query);
> $r = oci_execute($result);
> // Display an appropriate message
> if ($r) {
> echo "
Product successfully inserted!
";
> }else {
> echo "
There was a problem inserting the log book!
";
> $error = oci_error($conn);
> echo 'Insert failed. Oracle reports: ' . $error['message'];
>
> }
> //direct the user back to the entry form
>
> // Commit transaction
> $committed = oci_commit($conn);
> // Test whether commit was successful. If error occurred, return error message
> if (!$committed) {
> $error = oci_error($conn);
> echo 'Commit failed. Oracle reports: ' . $error['message'];
> }
> // Should have one affected row
> if ((oci_num_rows($result)== 0) ) {
> echo "
There was a problem inserting some of the selected items.
".oci_error().'
';
> // exit();
> } else {
> echo "
The selected items were successfully inserted.
";
> }
> displayDeleteForm();
> }
>
>
> //.......................................................... .................function showRecord()
>
> function showRecord() {
>
> global $fields;
> global $dFields;
> global $rowInsert;
> // Loop through each log_book_id with an enabled checkbox
> if (!isset($_POST['checkbox'])){
> return true;
> }
> //else
>
> foreach($_POST['checkbox'] as $key=>$val){
> $toDelete[] = $key;
> }
>
>
> $db = "(DESCRIPTION =
> (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
> (CONNECT_DATA =
> (SERVER = DEDICATED)
> (SID = LMKIIIGDNSID)
> )
> )";
> if ($conn=oci_connect('landon', 'rumprocella',$db))
> {
> echo "Successfully connected to Oracle.\n";
> }
> else
> {
> $err = OCIError();
> echo "Oracle Connect Error " . $err['message'];
> }
>
> // errors
> //get log_book_id table information
> $user = "select * from log_book_id where log_id = $toDelete[0]";
> $result = oci_parse($conn, $user);
> $r = oci_execute($result);
>
> //display log_book_id information
>
> $count = 0;
> $newArray = oci_fetch_assoc($result);
> if ($count == 0) print_r($newArray);
> $count = 1;
> foreach ($fields as $field){
> $fieldx = strtoupper($field);
> ${$field} = $newArray[$fieldx];
> $dFields[$field] = ${$field};
> }
> $rowID = $newArray['LOG_ID'];
> $rowInsert = $rowID;
> print_r($dFields);
> print ($rowInsert);
> //note that we do not rely on the checkbox value as not all browsers submit it
> //instead we rely on the name of the checkbox.
>
> // insert the row information in the entry form
> global $fields;
> //end validation
> displayEntryForm();
> }
>
> //.......................................................... .................function displayEntryForm()
> function displayEntryForm($errorMessages=null, $dFields=null){
> if (!empty($errorMessages)){
> echo "
".explode('
', $errorMessages) . "
";
> }
>
> global $dFields;
> //sort out field values
> global $fields;
> foreach ($fields as $field){
> if (isset($dFields[$field])){
> ${$field} = $dFields[$field];
> } else {
> ${$field} = '';
> }
> }
>
> echo <<
>
> HTML;
> } //end display function
> ?>
>
>
>
>
>
>
>
Have you tried the $_SESSION variable?
http://us.php.net/manual/en/reserved.variables.session.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: global not solving my problem
am 30.11.2008 20:48:35 von Fred Silsbee
--- On Sun, 11/30/08, Fred Silsbee wrote:
> From: Fred Silsbee
> Subject: global not solving my problem
> To: php-db@lists.php.net
> Cc: "Chris" , "Jack van Zanen"
> Date: Sunday, November 30, 2008, 6:35 PM
> problem:
>
> I have resolved all problems in the PHP program below
> except one.
>
> Yes I know the program is in a mess but I will clean it up.
>
> This is a learning exercise!
>
> Basically there is one function per page.
>
> When I make a selection on a page, a function is executed.
>
> I need to pass the value of $rowInsert from one page to
> another.
>
> $rowInsert is altered when I enter the program (at the
> top).
>
> To verify the program works (outside this problem), I set
> the value = 525.
>
> Global does not persist the value between pages(functions).
>
> I can't use _POST because the value of $rowInsert is
> not associated with an entry slot(edit control).
>
> I could make an entry slot(edit control) just for this
> purpose but that is not good!
>
>
>
>
>
>
>
>
> /*
> drop sequence log_id;
> create sequence log_id
> increment by 1
> start with 1;
>
> drop table log_book_id;
>
> create table log_book_id ( log_id number primary key, fdate
> date, actype varchar2(16), acid varchar(16), nlandings
> number, nhoursnumber);
>
> insert into log_book_id values (logid.nextval,
> TO_DATE('08/12/1973','MM/dd/YYYY'),'C150','N5787G',1,1.8);
>
> insert into log_book_id values (logid.nextval,
> TO_DATE('08/17/1973','MM/dd/YYYY'),'C150','N5787G',3,1.5);
>
> insert into log_book_id values (logid.nextval,
> TO_DATE('08/26/1973','MM/dd/YYYY'),'C150','N5787G',10,1.8);
>
> insert into log_book_id values (logid.nextval,
> TO_DATE('09/01/1973','MM/dd/YYYY'),'C150','N5293S',9,1.7);
> */
>
> print("........................................ENTER........ ........");
>
> $rowInsert = 525; // temporary
>
> $db = "(DESCRIPTION =
>
> (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT =
> 1521))
> (CONNECT_DATA =
>
> (SERVER = DEDICATED)
>
> (SID = LMKIIIGDNSID)
>
> )
>
> )";
>
> if ($conn=oci_connect('landon',
> 'rumprocella',$db))
>
> {
>
> echo "Successfully connected to
> Oracle.\n";
>
> }
>
> else
>
> {
>
> $err = OCIError();
>
> echo "Oracle Connect Error " .
> $err['message'];
>
> }
>
>
> //construct a global variable for the form profile
> $fields = array("fdate", "actype",
> "acid", "nlandings",
> "nhours");
> ///
>
>
> // If the submit button has been pressed
> if (isset($_POST['select'])){
> displayDeleteForm();
> }elseif(isset($_POST['delete'])){
> deleteRecords();
> } elseif(isset($_POST['insert'])){
> insertRecord();
> } elseif (isset($_POST['new'])){
> displayEntryForm();
> } elseif (isset($_POST['update'])){
> showRecord();
> } else {
> //default action
> displayEntryForm();
> }
>
> //.......................................................... .................function
> displayDeleteForm()
>
> function displayDeleteForm(){
> //get $fields into the function namespace
> global $fields;
> global $conn;
> /* Create and execute query. */
> // Loop through each row, outputting the actype and name
> echo <<
>
> Pilots Logbook entries stored in Oracle Relational
> Database
> under Redhat Fedora 8 Linux
>
>
> action="{$_SERVER['PHP_SELF']}"
> method="post">
>
> align="center" border="1">
>
>
>
>
checked
>
>
rowID
>
>
fdate
>
>
actype
>
>
acid
>
>
nlandings
>
>
nhours
>
>
>
> HTML;
>
>
> //get log_book_id table information
> $user = "select * from log_book_id";
> $result = oci_parse($conn, $user);
> $r = oci_execute($result);
>
> //display log_book_id information
>
> $count = 0;
> while ($newArray = oci_fetch_assoc($result)) {
> if ($count == 0) print_r($newArray);
> $count = 1;
> foreach ($fields as $field){
> $fieldx = strtoupper($field);
> ${$field} = $newArray[$fieldx];
> $count = $count +1;
> // print($field);
> // print_r($newArray[$field]);
> }
> $rowID = $newArray['LOG_ID'];
>
> //note that we do not rely on the checkbox value as
> not all browsers submit it
> //instead we rely on the name of the checkbox.
>
> echo <<
>
>
>
>
>
>
> name="checkbox[$rowID]"
> value="$rowID">Check to delete record
>