Tuesday, 9 June 2020

php references

try throw catch if it is tried, if its ok execute that,if tried false, throw the error and execute the catch






if it is tried, if its ok execute that,if tried false, throw the error and execute the catch
<?php
$loggedin = true;
if ($loggedin ){
echo 'welcome';
} else {
echo 'please log in';
}
?>
arrays and types
<?php
Array ( [0] => react [1] => angular [2] => vue )
$javascript = array("react", "angular", "vue"); array(3) { [0]=> string(5) "react" [1]=> string(7) "angular" [2]=> string(3) "vue" }
print_r ($javascript);
echo '<br>'; angular
var_dump($javascript);
echo "<h3>$javascript[1] </h3>"; array(3) { ["react"]=> string(8) "facebook" ["angular"]=> string(6) "google" ["vue"]=> string(8) "evan you" }
// associative array
facebook
$javascript_a = array (
react => "facebook", array(2) { [0]=> array(2) { ["userid"]=> string(5) "user1" ["password"]=> string(4) "1234" } [1]=> array(2) { ["userid"]=> string(5) "user2" ["password"]=> string(4) "4321" } }
angular => "google",
vue => "evan you" user1
);
var_dump($javascript_a);
echo "<h3>$javascript_a[react] </h3>";
// multi dimensional array
$users = array (
array( "userid" => "user1", "password" => "1234"),
array( "userid" => "user2", "password" => "4321")
);
var_dump($users);
echo '<h3>' . $users[0]["userid"] .'</h3>';
?>
loops
to do repetitve task
<?php
echo '<h1> while loop </h1>';
$limit = 10;
$number = 0;
echo "<u1>";
while ($number <= $limit) {
echo "<li> $number </li>";
$number++;
}
echo "</ul>";
echo "<hr>";
// for loop
echo '<h1> for loop </h1>';
echo "<ul>";
for ($i=0; $i <= $limit; $i++){
echo "<li> $i </li>";
}
echo "</ul>";
//do while loop
echo "<h1> do while loop </h1>";
$number = 0;
echo "<ul>";
do {
echo "<li> $number </li>";
$number++;}
while ($number <= $limit);
// for each loop
echo '<h3> for each loop </h3>';
$names = array ("bob", "jane", "charlie");
echo "<ul>";
foreach ($names as $name){
echo "<li> $name </li>";
}
echo "</ul>";
//forechloop
echo '<h3> for each loop </h3>';
$languages = array (
php => "laravel",
python => "django"
);
echo "<ul>";
foreach ($languages as $language => $framework){
echo "<li> frame work for language: $framework </li>";
}
echo "</ul>";
?>
<?php
function sayhi(){
echo "hi everyone";
}
sayhi();
sayhi();
sayhi();
?>
<?php
function add($num1, $num2){
return $num1+ $num2;
}
echo '<h4> the sum of 20 and 30 is ' . add(20,30);
?>
login page
<?php
?>
<form action="dashboard.php" method="post">
<input type ="text" name ="userid">
<input type="password" name ="password">
<input type ="submit" value="login">
</form>
<?php
$userid = $_POST["userid"];
$password = $_POST["password"];
if ($userid == "gtcoding" && $password =="123456"){
echo "<h1> welcome . $userid </h1>";
} else {
echo "incorrect login details";
}
?>
index.php
<?php include "header.php"; ?>
<h4 class="page1" > page 1 </h4>
<?php include "footer.php"; ?>
header.php
<!DOCTYPE html>
<html>
<head>
<title> gtcoding </title>
<link rel ="stylesheet" type ="text/css" href ="style.css">
</head>
<body>
<header>
<h1> gtcoding </h1>
<ul>
<li> <a href="index.php"> page1 </a> </li>
<li> <a href="page2.php"> page2 </a> </li>
</ul>
</header>
</body>
</html>
footer.php
<html>
<body>
<footer>
<P> this website is created by gt coding </p>
</footer>
</body>
</html>
page2.php
<?php include "header.php"; ?>
<h4 class="page2" > page 2 </h4>
<?php include "footer.php"; ?>
<?php require "header1.php"; ?>


<h4 class="page1" > page 1 </h4>
<?php include "footer.php"; ?>
<?php include "header1.php"; ?>
<h4 class="page1" > page 1 </h4>
<?php include "footer.php"; ?>

No comments:

Post a Comment