Академический Документы
Профессиональный Документы
Культура Документы
Programming
• Before you continue you should have a basic
understanding of the following:
• HTML
• CSS
• JavaScript
• What is PHP?
• PHP is an acronym for "PHP: Hypertext Preprocessor“
• The PHP Hypertext Preprocessor (PHP) is a programming
language that allows web developers to create dynamic
content that interacts with databases.
<?php
$txt = “www.tpsc.ac.tz";
echo "I love $txt!";
?>
</body>
</html>
<?php
$txt = "W3Schools.com";
echo "I love " . $txt . "!";
?>
</body>
</html>
• Syntax
if (condition)
code to be executed if condition is true;
elseif (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
<form action="welcome_get.php"
method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type=“email" name="email"><br>
<input type="submit">
</form>
</body>
</html>
Prepared by Madam Amina
Cont.
• When the user fills out the form above and
clicks the submit button, the form data is sent
for processing to a PHP file named
"welcome.php". The form data is sent with
the HTTP GET method.
• To display the submitted data you could
simply echo all the variables. The
"welcome.php" looks like this:
• <html> <head>
tutorials_inf table .
<title>Selecting Table in MySQLi Server</title>
</head> <body>
• <?php
• $conn = mysqli_connect(“localhost”,”root”,””,”TUTORIALS”); if(!
$conn ) {
• die('Could not connect: ' . mysqli_error());
• }
• echo 'Connected successfully<br>';
• $sql = 'SELECT name FROM tutorials_inf';
• $result = mysqli_query($conn, $sql);
• if (mysqli_num_rows($result) > 0) {
• while($row = mysqli_fetch_assoc($result)) {
• echo "Name: " . $row["name"]. "<br>"; }
• } else { echo "0 results"; }
• mysqli_close($conn);
• ?>
• </body></html>
Prepared by Madam Amina
Fetching Data Using PHP Script:
• if (mysqli_num_rows($result) > 0) {
• while($row = mysqli_fetch_assoc($result)) {
• echo "Name: " . $row["first_name"]." ". $row["last_name"]." ".
$row["email_address"]."<br>";
• }
• } else {
• echo "0 results";
• }
• mysqli_close($conn);
• ?>
Prepared by Madam Amina
Updating Data Using PHP Script
• WELCOME</br>
• <a href="logout.php"> logout</a>
• </body>
• </html>