Most Popular Programming Languages
Most Popular Programming Languages
Most Popular Programming Languages
languages
Most Popular programming
languages
Most-Used Programming Languages
• To find out what programming languages are
most used today, we looked at GitHub pushes.
Not surprisingly, a lot of legacy languages top
this list. Here are the top 20 programming
languages by total GitHub pushes:
• https://stackify.com/trendiest-programming-
languages-hottest-sought-programming-
languages-2017/
• Based on job listings on Indeed as of March
2017, here are the top 10 programming
languages currently in demand among
companies seeking developer talent:
Working with Databases
2. The web server receives the request for results.php, retrieves the
file, and passes it to the PHP engine for processing.
11
3. The PHP engine begins parsing the script.
– Inside the script is a command to connect to the database and
execute a query (perform the search for books).
– PHP opens a connection to the MySQL server and sends on the
appropriate query.
13
1
Browser 6
Web Server
5 2
MySQL Server 4
PHP Engine
14
XAMPP
• Install XAMPP to the root directory: C:\XAMPP
• Launch XAMPP control panel and start the
following services:
MySql
Apache
• Open your web browser and enter in the URL
box:
http://localhost
Running XAMPP Error: Object not
found
• Go to XAMPP Control Panel
• Click on config (APACHE)
• Select Apache(httpd.conf)
• Search for “DocumentRoot”
• Look at the path pointing to the htdocs folder.
e.g "C:/xampp/htdocs“
Or "C:/Users/xampp/htdocs"
Your first PHP application
• Navigate to “C:\XAMPP\htdocs” echo'Hello World';
echo"Hello PHP";
• Create a project folder called Print "Hello PHP World";
HelloPHP Print "GoodBye World!";
• Inside the folder create a file with ?>
a .php extension called Hello
World. </body>
• Write the following code into the </html>
file:
• Notice how echo ‘5x5=$foo’ outputs $foo rather than replacing it with 25
• Strings in single quotes (‘ ’) are not interpreted or evaluated by PHP
• This is true for both variables and character escape-sequences (such as
“\n” or “\\”)
Print
• Echo has no return value while print has a
return value of 1 so it can be used in
expressions.
• echo can take multiple parameters (although
such usage is rare) while print can take one
argument.
• The echo statement can be used with or
without parentheses: echo or echo().
Echo with HTML
• <?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with
multiple parameters.";
?>
Example
• <?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
$x = 5;
$y = 4;
echo "<h2>$txt1</h2>";
echo "Study PHP at $txt2<br>";
echo $x + $y;
?>
Example - Print
• <?php
print "<h2>PHP is Fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";
?>
Example - Print
• <?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
$x = 5;
$y = 4;
print "<h2>$txt1</h2>";
print "Study PHP at $txt2<br>";
print $x + $y;
?>
Arithmetic Operations
• $a - $b // subtraction
• $a * $b // multiplication
• $a / $b // division
• $a += 5 // $a = $a+5 Also works for *= and /=
Concatenation
• Use a period to join strings into one.
Escaping the Character
• If the string has a set of double quotation
marks that must remain visible, use the \
[backslash] before the quotation marks to
ignore and display them.
• Run the php script below from the browser as
localhost.
PHP Control Structures
Control Structures: Are the structures within a language that
allow us to control the flow of execution through a program or
script.
Grouped into conditional (branching) structures (e.g. if/else)
and repetition structures (e.g. while loops).
Example if/else if/else statement:
if ($foo == 0) {
echo ‘The variable foo is equal to 0’;
}
else if (($foo > 0) && ($foo <= 5)) {
echo ‘The variable foo is between 1 and 5’;
}
else {
echo ‘The variable foo is equal to ‘.$foo;
}
If ... Else...
• If (condition)
{
Statements;
}
Else
{
Statement;
} No THEN in PHP
While Loops
• While (condition)
{
Statements;
}
Date Display
• Or
Month, Day & Date Format Symbols
M Jan
F January
m 01
n 1
Day of Month d 01
Day of Month J 1
Day of Week l Monday
Day of Week D Mon
Functions
• php2.php
Practice questions
• Click on phpMyadmin
• Click on Databases
• Enter db name (myDB) and click on create
• Click on the database name(to the left) and enter a table name
Students, specify 3 columns for it and click on Go.
• Enter 3 column names (name, Surname and RegNo) of type
VarChar and length 20 and click on Save
• Click on SQL,delete the query that’s appearing and enter the
following query:
Click on Go.
Working on a database from the browser
• Create a new notepad document,
TableStudents.php and save it in
C:\XAMPP\htdocs
• Open the document and save the following
information
1. Viewing database content in
browser
Viewing Database contents from
browser
<?php $table .="</table>";
// connect to database
if(!$con=mysql_connect("127.0.0.1","root","","myD ?>
B"))
{ <html>
die("Error connecting to database"); <head><title></title></head>
exit(); <body>
} <fieldset>
mysql_select_db("myDB"); <legend>List of Students</legend>
<?php
//selecting from the database echo "<br><br><u><b>IS
223</b></u><br></br>";
$sql="select name from Students";
$rs=mysql_query($sql); //reading contents of variable
$table="<table border='1'>";
$table .="<tr><td><b>Student</b></td></tr>"; echo $table;
?>
//storing data into variable
</fieldset>
while($row = mysql_fetch_array($rs)){ </body>
</html>
$table.="<tr><td>".$row["name"]."</td>
</tr>";
}
Viewing DB from browser
• Go to browser
• Type in the URL Box:
localhost/TableStudents.php
• The following page should appear in browser:
2. Inserting values into database from
browser
Inserting values into DB from browser
Command Syntax:
<body>
<h1>A small example page to insert some data in to the MySQL database using PHP</h1>
</form>
</body>
</html>
<head>
<title> Log In </title>
</head>
<body>
<div class="login-page">
<div class="form">
<form class="login-form" method="POST" action="Login.php">
<input type="text" placeholder="Student Name" name="user"/>
<input type="password" placeholder="Registration Number" name="pass"/>
<button>login</button>
<p class="message">Not registered?
<a href="#">Create an account</a>
</p>
</form>
</div>
</div>
</body>
</html>
LogIn.php
<?php echo "SUCCESSFULLY LOGIN TO USER PROFILE
PAGE...";
$con = mysql_connect("127.0.0.1","root","","myDB"); header("Location: AfterLogIn.php");
if (!$con) }
{ else
die('Could not connect: ' . mysql_error()); {
} echo "SORRY... YOU ENTERD WRONG ID AND
else PASSWORD... PLEASE RETRY...";
{ }
echo "Connection successful"; }
}
mysql_select_db("myDB", $con); ?>
<html>
<body>
<p>
Congratulations for successfully logging into the dummy
web-site.
</p>
</body>
</html>
Practice Questions
Question
a) Create the interface shown below and use it to
insert some data into a database and to retrieve &
view the data in a table:
b) Edit the form on the previous page so that the
user can click on a button labelled Edit.
• When this button is clicked, a modal appears
containing textboxes that allows the user to
edit the information in the database.