Unformatted text preview:

SSE 3200 PhP Lab (Part 2 of 2)IntroductionRecall that Php runs on the server rather than on the web browser (client). The following are thesteps needed to run a php program, say, MyPhp.php:• Write and save MyPhp.php in the .WWW-orion directory you created earlier.• Check the permissions and verify that it has read permissions for group and others:Enter this command: ls -l MyPhp.phpIt will display something similar to:-rw-r--r-- 1 nilufer csdept 542 2010-03-25 10:04 MyPhp.phpIf you don’t see the last two r’s, enter: chmod og+r MyPhp.php• Access your program from the web using the following URL :http://orion.csl.mtu.edu/∼your-user-name/MyPhp.php• The pages that are referenced are at:http://www.w3schools.com/php/Date1. Go to the PHP Date page under PHP Advanced at http://www.w3schools.com/php/default.aspand read it.2. Write and run the following example (call it date01.Php):<?phpecho "Today is: <br />";echo date("m/d/Y") . "<br />";echo date("Y/m/d") . "<br />";echo date("Y.m.d") . "<br />";echo date("Y-m-d")?>Note that it prints the date in different orders for day, month and year. The string concatena-tion operator is a dot (.), as opposed to a plus (+) in Javascript. The “>” character for theline-break tag must be entered as a special character.1Now, we would like indent the lines under the first line. Add two spaces before each date:<?phpecho "Today is: <br />";echo " " . date("m/d/Y") . "<br />";echo " " . date("Y/m/d") . "<br />";echo " " . date("Y.m.d") . "<br />";echo " " . date("Y-m-d")?>Did it work? Tell me the reason.3. Date returns today’s date by default. Other dates can be created using mktime:mktime(hour,minute,second,month,day,year,is-dst)To go one day in the future we simply add one to the day argument of mktime():<?php$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));echo "Tomorrow is " . date("Y/m/d", $tomorrow);?>To refer to a specific date such as 01/01/2010 enter:<?php$date1 = mktime(0,0,0,1,1,2010);echo "Date1 is: " . date("Y/m/d ", $date1);?>To print the day of the week, add the following line. The character in quotes is lowercase“L”.echo date("l", $date1);4. The date("U", $date2) statement finds the number of seconds since the start date of1970/01/01. Each day is 86,400 seconds (Javascript used milliseconds). Find how manydays passed since your birthday using Php.25. It is even possible to find the time of sunrise for a given date. Type and run the followingprogram (call it sunrise.php). You do not need to enter the comments.<?php// Calculate the sunrise time for Houghton, Michigan// Latitude: 47.1 North// Longitude: 88.6 West (enter as a negative number below.)// Zenith ˜= 90// offset: +1 GMTecho("Date: " . date("D M d Y") . "<br />");echo("Sunrise time: ");echo(date_sunrise(time(),SUNFUNCS_RET_STRING,47.1,-88.6,90, -4));?>3Forms1. Here is a simple setup that displays two form fields and uses the contents to display a re-sponse. Notice that both files have html as their main content. Type and save the followinginto a file named form01.php.<html><body><form action="form01a.php" method="post">Name: <input type="text" name="fname" />Favorite day: <input type="text" name="day" /><input type="submit" value="Submit data" /></form></body></html>Type and save the following into a file named form01a.php:<html><body>Welcome <?php echo $_POST["fname"]; ?>!<br />I also like <?php echo $_POST["day"]; ?>.</body></html>The first HTML file displays two form fields and a button to submit the contents of thesefields. The program in form01a.php is invoked when the data is submitted using thisform.2. Read the pages on PHP Forms, PHP $ GET and PHP $ POST. These are the last three itemsunder PHP Basic.4Checking the MySQL databases that were set for youPlease check that the databases that were created for you are working. You will access the databasedirectly from the command line. We will use Php programs later.• Connect to orion’s mysql server. Enter your account name in place of userid:mysql -h orion.csl.mtu.edu -u userid -pYou will be prompted for a password. It was set to your account name. If you login suc-cessfully, all the remaining commands will be entered into mysql. You will see the promptmysql>.• See the list of available databases. One of the lines should be a database with your accountname.mysql> show databases;• Switch to your database, replace userid with your account name:mysql> use userid;• Select the database:mysql> select database();• Create a temporary table.mysql> create table t1 (temp int(4));• Show the new table.mysql> describe t1;• Delete the new table.mysql> drop table t1;• Exit mysql.mysql>


View Full Document

MTU SSE 3200 - LECTURE NOTES

Download LECTURE NOTES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view LECTURE NOTES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view LECTURE NOTES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?