1 / 10

CS242

CS242. PHP. PHP. PHP - hypertext pre-processor PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML PHP is a server-side technology. That is, action is taken by the server, not the user's computer. What you need.

taya
Download Presentation

CS242

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS242 PHP

  2. PHP • PHP - hypertext pre-processor • PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML • PHP is a server-side technology. That is, action is taken by the server, not the user's computer.

  3. What you need • server like Apache • PHP • recommended: MySQL

  4. Example PHP/HTML <html><head><title>PHP Test</title></head><body> <?php echo '<p>Hello World</p>'; ?> </body> </html>

  5. View-> Source(Output) <html> <head> <title>PHP Test</title> </head> <body> <p>Hello World</p> </body> </html>

  6. Connecting to a database $db = mysql_connect("localhost", "root"); mysql_select_db("mydb",$db); $result = mysql_query("SELECT * FROM employees",$db);

  7. Results of a Query $result = odbc_exec($db,$query); if ($myrow = odbc_fetch_array($result)) { // output HTML code here to begin the table // echo "<table border=1 bgcolor=\"#666666\">\n"; do { printf("<tr bgcolor=\"#999999\"><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", $myrow ["date"], $myrow["time"], $myrow["Slot 1"], $myrow["Slot 2"], $myrow["Slot 3"]); $myrow = odbc_fetch_array($result); } while ($myrow["date"]!=""); // end the table started above // echo "</table>"; }

  8. Result Sets <?php $db = mysql_connect("localhost", "root"); mysql_select_db("mydb",$db); $result = mysql_query("SELECT * FROM employees",$db); echo "<table border=1>\n"; echo "<tr><td>Name</td><td>Position</tr>\n"; while ($myrow = mysql_fetch_row($result)) { printf("<tr><td>%s %s</td><td>%s</td></tr>\n", $myrow[1], $myrow[2], $myrow[3]); } echo "</table>\n"; ?>

  9. Using a Form to get data <form action="action.php" method="post"> <p>Your name: <input type="text" name="name" /></p> <p>Your age: <input type="text" name="age" /></p> <p><input type="submit" /></p> </form>

  10. $PHP_SELF The filename of the currently executing script, relative to the document root. http://www.phpfreaks.com/phpref/34.php $current_url = $_SERVER['PHP_SELF']; Then $current_url is “phpref/34.php”

More Related