Cs 223 Programming Languages
Cs 223 Programming Languages
CHAPTER 1
0101-WHAT IS PHP?
PHP is easy to learn and PHP is also free to download it. PHP code is simpler than other
server language such as Java(J2EE) or MS ASP.
RUNNING IN PHP
• A server must have a Runtime PHP software installed in order to process PHP.
• Generally, the output from a PHP program is an HTML page.
• PHP programs are called Web Page and return new Web Pages to the browser and
the result
CHAPTER 2
• Internet Connection
Research PHP.net
Research MySQL.com (it’s really an Oracle)
In the wamp you can find WWW is called directory where you can run programs. In running PHP
programs, go to your local browser and change www to localhost and put the enter key to run it.In
running local host you can see the configuration and some tools, so therefore you can now run
programs on the installed server.
To test the connection of PHP and MySQL, tap testmysql.php and it will work right away.
See in Figure 2, there are bunch of errors while running the program, there will be some changes
inside the program. Look at the figure below:
Figure 4: To connect or have access you can just type mysql_connect.
Figure 7: To easier access, erase the word dbpassword and just leave it blank ‘ ’
Figure 8: Refresh your local browser and you will find notice that your system is now
connected to your server.
<?php
$link = mysqli_connect ('localhost','root','');
if (!$link) {
die('Could not connect to MySQL; ' . mysqli_error());
}
echo 'Connection OK'; mysqli_close($link);
?>
This is the actual code that is being revise to make the your system accessed on your server.
Figure 10: A data is being put inside the box for access.
Figure 11: A significance that you are able to run your php code.
<html>
<head>
<title>HTML Forms</title>
<link rel="stylesheet" type="text/css" href="css/basic.css"/>
</head>
<h3>Success!</h3>
<?php
$firstname = $_POST['firstname'];
print "<p>Congratulations $firstname</p>";
?>
</body>
</html>
Figure 12
Figure 13
Figures 12 and 13 the actual output of the program in HTML and PHP forms.
Chapter 3
Using a PHP Print Tags
<html>
<head><title>0301 Usinh PHP Scrip.Tags</title>
<style>body {font-family: Arial, Helvetica, sans-serif; font-size: 16px;}</style>
<body>
<hl>0301 Using PHP Script Tags</hl>
<p>What are script tags and why do we need them to run PHP?</p>
<?php
$today = date('y-m-d h:g:s');
print "<p><b>Today is $today </b></p>";
?>
<p>Do you want to see that again?</p>
<?php
print "<p><b>Today is STILL $today </B></p>";
?>
</body>
</html>
Remember to validate your HTML using tools like the W3C Markup Validation
Service and test it on multiple browsers to ensure consistent display.