Thursday, October 06, 2005
PHP!
I finally got to work on my first experience with PHP programming on tuesday! Russel Dover helped me out a lot, and showed me many of the basics. It seems pretty straightforward, just a matter of getting the syntax down. Here is some of the code
/////////////////////////////////////////////////////////////////////
//
//This PHP file interacts with the mySQL Database at CLSG. Three outputs can occur, create new, edit, or delete. INSERT, UPDATE, DELETE are the three basic commands that are used to have this operation carry out successfully.
//
//
//
// Input: Data from form on addform.dsp.php, along with hyperlink properties of index.dsp.php.
//
//
// Output: the numbers, the sum (integer) and the average (double) of all
//
//
// Date: October 4, 2005
//
// Author: Joe Trapani, Russel Dover
//
// File: addform.act.php
//
//////////////////////////////////////////////////////////////////////
//Used to Edit Vars of existing data.
$status = $HTTP_GET_VARS['status'];
$activityid = $HTTP_GET_VARS['activity'];
//Used to Create a new row of data.
if($status == ""){
$status = $HTTP_POST_VARS['status'];
}
//Uses MySQL Delete Command to erase an entire row from the database.
if($status == 'delete'){
$query = "DELETE FROM portal..HOUSE_ACTIVITY WHERE houseactivityid = ".$activityid;
$_DB->query($query);
// Redirect back to index page.
header('location: /joe/house/index.php');
exit;
}
//If a link was used to access this page then update the data, else create new.
if($status == 'update'){
if($HTTP_POST_VARS['Save'] == 'Save'){
//$activityid = $HTTP_POST_VARS['activity'];
$activityName = $HTTP_POST_VARS['activity_name'];
$desc = $HTTP_POST_VARS['description'];
//Calling a number doesn't require '' around it.
//This line updates the portal by setting the variable names with the choosen names.
$query = "UPDATE portal..HOUSE_ACTIVITY SET activity='".$activityName."', description='".$desc."' WHERE houseactivityid = ".$activityid;
//Writes the information to the Database.
$_DB->query($query);
//Prints out the variable query for testing.
//echo $query;
// Redirect back to index page.
header('location: /joe/house/index.php');
exit;
}
}else{
if($HTTP_POST_VARS['Save'] == 'Save'){
//Used to Post Vars to create a new set of data.
$activityName = $HTTP_POST_VARS['activity_name'];
$desc = $HTTP_POST_VARS['description'];
// '' is for the string, and " is for a variable inputed. The . joins the sting. together.
//This line inserts the new data from the form to the database, portal..House_ACTIVITY (Portal Name, Db 1, Db 2, House Activity Db) then Cols Names with Values to be added.
$query = "INSERT into portal..HOUSE_ACTIVITY (activity,description) VALUES ('".$activityName."', '".$desc."')";
//Prints out the variable query.
//echo $query;
//obj db calls query function to execute var. $query.
$_DB->query($query);
// Redirect back to index page.
header('location: /joe/house/index.php');
exit;
}
}
//Calls the data in from the Db using the SELECT command; the Houseactivityid is used to verify the correct row to edit on the table.
$query = "SELECT activity, description FROM portal..HOUSE_ACTIVITY WHERE houseactivityid = '" .$activityid. "'";
//Command for the database to fetch the existing data to be edited.
$existingData = $_DB->query_fetch($query);
?>
I'm quite proud of this, becuase it took about 6 hours to do, even with much of the help that Russell gave me.
On other news, I went out to Club Rocket last night, and celebrated a birthday of one of the girls on the trip. It was a pretty good time, despite that the ride on the buses back at 3am were a bit confusing since we've never taken them before. It worked out in the end and we got home just fine. I hava quite a bit of homework this weekend so I won't be doing much. Well until next time!
-Joe
/////////////////////////////////////////////////////////////////////
//
//This PHP file interacts with the mySQL Database at CLSG. Three outputs can occur, create new, edit, or delete. INSERT, UPDATE, DELETE are the three basic commands that are used to have this operation carry out successfully.
//
//
//
// Input: Data from form on addform.dsp.php, along with hyperlink properties of index.dsp.php.
//
//
// Output: the numbers, the sum (integer) and the average (double) of all
//
//
// Date: October 4, 2005
//
// Author: Joe Trapani, Russel Dover
//
// File: addform.act.php
//
//////////////////////////////////////////////////////////////////////
//Used to Edit Vars of existing data.
$status = $HTTP_GET_VARS['status'];
$activityid = $HTTP_GET_VARS['activity'];
//Used to Create a new row of data.
if($status == ""){
$status = $HTTP_POST_VARS['status'];
}
//Uses MySQL Delete Command to erase an entire row from the database.
if($status == 'delete'){
$query = "DELETE FROM portal..HOUSE_ACTIVITY WHERE houseactivityid = ".$activityid;
$_DB->query($query);
// Redirect back to index page.
header('location: /joe/house/index.php');
exit;
}
//If a link was used to access this page then update the data, else create new.
if($status == 'update'){
if($HTTP_POST_VARS['Save'] == 'Save'){
//$activityid = $HTTP_POST_VARS['activity'];
$activityName = $HTTP_POST_VARS['activity_name'];
$desc = $HTTP_POST_VARS['description'];
//Calling a number doesn't require '' around it.
//This line updates the portal by setting the variable names with the choosen names.
$query = "UPDATE portal..HOUSE_ACTIVITY SET activity='".$activityName."', description='".$desc."' WHERE houseactivityid = ".$activityid;
//Writes the information to the Database.
$_DB->query($query);
//Prints out the variable query for testing.
//echo $query;
// Redirect back to index page.
header('location: /joe/house/index.php');
exit;
}
}else{
if($HTTP_POST_VARS['Save'] == 'Save'){
//Used to Post Vars to create a new set of data.
$activityName = $HTTP_POST_VARS['activity_name'];
$desc = $HTTP_POST_VARS['description'];
// '' is for the string, and " is for a variable inputed. The . joins the sting. together.
//This line inserts the new data from the form to the database, portal..House_ACTIVITY (Portal Name, Db 1, Db 2, House Activity Db) then Cols Names with Values to be added.
$query = "INSERT into portal..HOUSE_ACTIVITY (activity,description) VALUES ('".$activityName."', '".$desc."')";
//Prints out the variable query.
//echo $query;
//obj db calls query function to execute var. $query.
$_DB->query($query);
// Redirect back to index page.
header('location: /joe/house/index.php');
exit;
}
}
//Calls the data in from the Db using the SELECT command; the Houseactivityid is used to verify the correct row to edit on the table.
$query = "SELECT activity, description FROM portal..HOUSE_ACTIVITY WHERE houseactivityid = '" .$activityid. "'";
//Command for the database to fetch the existing data to be edited.
$existingData = $_DB->query_fetch($query);
?>
I'm quite proud of this, becuase it took about 6 hours to do, even with much of the help that Russell gave me.
On other news, I went out to Club Rocket last night, and celebrated a birthday of one of the girls on the trip. It was a pretty good time, despite that the ride on the buses back at 3am were a bit confusing since we've never taken them before. It worked out in the end and we got home just fine. I hava quite a bit of homework this weekend so I won't be doing much. Well until next time!
-Joe