php and some uses
PHP
Difference between php and html PHP :
the difference between php and html PHP is a
server-side scripting language, while HTML is a client-side markup language.
PHP is used to create dynamic web pages that interact with databases, while
HTML is used to structure and present content on a webpage. PHP is a
programming language, while HTML is a markup language. PHP code is executed on
the server, while HTML code is rendered in the browser.
What is dynamic web site :
A dynamic website is a website that is
constantly changing and displaying different content each time it is accessed.
It is created using a combination of server-side programming languages, such as
PHP, ASP, or JSP, and a database, such as MySQL. Dynamic websites are often
used for e-commerce, online communities, and other interactive applications.
Example of php request mysql connect :
// Check connection
if ($conn->connect_error) {
die("Connection failed: " .
$conn->connect_error);
}
echo "Connected successfully";
?>
Create php index page :
<?php
// Include the header
include('header.php');
?>
<!-- HTML Content -->
<h1>Welcome to My Website</h1>
<p>This is the homepage of my website.
Here you can find information about my services and products.</p>
<?php
// Include the footer
include('footer.php');
?>
Insert image with php :
You can use the <img> tag to insert an
image with PHP. <?php echo '<img src="image.jpg" alt="My
Image">'; ?>
Insert link with php :
You can use the <a href="<?php
echo $url; ?>">link</a> to insert a link with PHP.
Create table with php :
<?php $servername = "localhost";
$username = "username"; $password = "password"; $dbname =
"myDB"; // Create connection $conn = new mysqli($servername,
$username, $password, $dbname); // Check connection if
($conn->connect_error) { die("Connection failed: " .
$conn->connect_error); } //
Create iterative instruction with php
<?php // Iterative instruction to print
out the numbers from 1 to 10 for ($i = 1; $i <= 10; $i++) { echo $i .
"\n"; }
Create conditional instruction with php
<?php if (condition) { // code to be
executed if condition is true } else { // code to be executed if condition is
false } ?>
Commentaires
Enregistrer un commentaire