├── first php.php ├── README.md ├── do-While Loops in php.php ├── dbs.php ├── variable.php ├── foreach Loops in php.php ├── For Loops in php.php ├── Date Function.php ├── web.php ├── Scope, Local & Global Variables.php ├── Switch Case Statements in php.php ├── While Loops in php.php ├── more on variable.php ├── If Else Conditionals in Php.php ├── Associative Arrays.php ├── connecting to a mysqali database.php ├── String Functions in Php.php ├── creating_mysqaldatabase.php ├── Creating a Table in MySQL using php.php ├── delete data.php ├── Functions in Php.php ├── Insert Data Into MySQL.php ├── Data Types in Php.php ├── Selecting and Displaying Data From MySQL.php ├── Updating Records in PHP.php ├── multipledesmensonalarry.php ├── Operators in Php.php ├── indexbootstrap.php ├── get and post form.php ├── Bootstrap Form and Saving Data.php └── fetch.php /first php.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP-AND-MYSQL 2 | ![1](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQDhv-irqMD1x7GuutODY7qLTGhah-1u5xakg&usqp=CAU) 3 | 4 | At first download xampp then 5 | Then download this file and paste in htdoc folder inside xampp. 6 | -------------------------------------------------------------------------------- /do-While Loops in php.php: -------------------------------------------------------------------------------- 1 | "; 3 | 4 | /*do{ 5 | some lines of code to be executed 6 | .. 7 | 8 | }while (condition)*/ 9 | 10 | 11 | $i= 0; 12 | 13 | do{ 14 | echo "$i
"; 15 | $i++; 16 | }while($i<5) 17 | 18 | ?> -------------------------------------------------------------------------------- /dbs.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /variable.php: -------------------------------------------------------------------------------- 1 | "; 8 | // variable is case sencitive for example name and nameE anything 9 | echo"$identity is a good and pure boy
"; 10 | 11 | ?> -------------------------------------------------------------------------------- /foreach Loops in php.php: -------------------------------------------------------------------------------- 1 | "; 3 | $arr = array("bananas","apple","harpic"); 4 | 5 | // for ($i=0; $i < count($arr); $i++){ 6 | // echo "$arr[$i]" ; 7 | // echo "
"; 8 | //} 9 | 10 | 11 | // better way to do thiis foreach loops 12 | foreach($arr as $value){ 13 | echo "$value
"; 14 | } 15 | ?> -------------------------------------------------------------------------------- /For Loops in php.php: -------------------------------------------------------------------------------- 1 | "; 4 | 5 | for ($index=1; $index <6 ; $index++){ 6 | // for (initialization;conditon;updation) 7 | echo "the number is $index
"; 8 | } 9 | //avoid running into infinite loops if you remove the plus 10 | for ($i=0; $i < 87; $i++){ 11 | echo $i; 12 | } 13 | 14 | echo "for lops has ended"; 15 | ?> -------------------------------------------------------------------------------- /Date Function.php: -------------------------------------------------------------------------------- 1 | "; 3 | $d = date ("d S F Y,g:i A"); 4 | echo "todays date is $d
"; 5 | echo date("l js \of F Y h:i:s:A"); 6 | echo "July l,2000 is on a
" .date("l", mktime(0,0,0,7,0,2000)); 7 | 8 | echo date ("l js \of F Y h:i:s A"); 9 | 10 | $year = date("y"); 11 | echo"
"; 12 | echo"copiright $year | All rights reserved
"; 13 | 14 | ?> -------------------------------------------------------------------------------- /web.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | <?php 9 | echo "Hello world"; ?> 10 | 11 | 12 | 16 | 17 | -------------------------------------------------------------------------------- /Scope, Local & Global Variables.php: -------------------------------------------------------------------------------- 1 | "; 4 | function printValue(){ 5 | // $a = 97; local variable 6 | echo "value of variable is $a"; 7 | } 8 | 9 | $a = 98; 10 | $b = 9; 11 | global $a,$b; 12 | // global varable 13 | echo "the value of your variable is $a and $b
" ; 14 | echo var_dump($GLOBALS["b"]); 15 | echo var_dump($GLOBALS["a"]); 16 | 17 | ?> -------------------------------------------------------------------------------- /Switch Case Statements in php.php: -------------------------------------------------------------------------------- 1 | "; 8 | break; 9 | 10 | case 45: 11 | echo"you are 45 years old
"; 12 | break; 13 | case 56: 14 | echo"you are 56 years old
"; 15 | break; 16 | default: 17 | echo"your age is weird
"; 18 | break; 19 | } 20 | 21 | 22 | ?> -------------------------------------------------------------------------------- /While Loops in php.php: -------------------------------------------------------------------------------- 1 | "; 4 | // echo 1;echo"
"; 5 | // echo 2;echo"
"; 6 | // echo 3;echo"
"; 7 | // echo 4;echo"
"; 8 | // echo 5;echo"
"; 9 | $i = 0; 10 | $x = 1; 11 | while($i<50 && $x<60){ 12 | echo "the value of i is"; 13 | echo $i+1; 14 | echo "
"; 15 | // we can add html tags 16 | // we can change the value of I in i+=3 so it will plus by three 17 | $i++; 18 | $x+=4; 19 | } 20 | 21 | ?> -------------------------------------------------------------------------------- /more on variable.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 |

more on php variable

11 | 15 | 16 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /If Else Conditionals in Php.php: -------------------------------------------------------------------------------- 1 | 78 ){ 8 | echo "a is s greater then 78"; 9 | } 10 | else{ 11 | echo "a is not greater 78 "; 12 | } 13 | 14 | echo"
"; 15 | 16 | $age = 74; 17 | 18 | if ($age>18){ 19 | echo "who can not eat Briyani it is very spicy."; 20 | } 21 | elseif($age>13){ 22 | echo"you can eat biriyani"; 23 | } 24 | 25 | 26 | // create an if else ladder more than elseif write a program to allow a driver to drive only when his age is greater than 25 an d less than 65 27 | 28 | 29 | ?> -------------------------------------------------------------------------------- /Associative Arrays.php: -------------------------------------------------------------------------------- 1 | "; 5 | echo $arr[0]; 6 | echo $arr[1]; 7 | echo $arr[2]; 8 | 9 | // associative arrays 10 | //numeric arry it has index or indexed array 11 | $favcol = array('tanbir' => 'red','rohan' => 'green','harry' => 'red', 8=>'this' 12 | ); 13 | // echo $favcol['tanbir']; 14 | // echo"
"; 15 | // echo $favcol['rohan']; 16 | // echo"
"; 17 | // echo $favcol[8]; 18 | 19 | foreach ($favcol as $key => $value){ 20 | echo "
favorite color of $key is $value"; 21 | } 22 | 23 | 24 | ?> -------------------------------------------------------------------------------- /connecting to a mysqali database.php: -------------------------------------------------------------------------------- 1 | "; 3 | /* 4 | Ways to connect to a MySQL Database 5 | 1. MySQLi extension 6 | 2. PDO 7 | */ 8 | // Connecting to the Database 9 | $servername = "localhost"; 10 | $username = "root"; 11 | $password = ""; 12 | // $database = "phpmyadmin tutorial"; 13 | 14 | // Create a connection 15 | $conn = mysqli_connect($servername, $username, $password); 16 | 17 | // Die if connection was not successful 18 | if (!$conn){ 19 | die("Sorry we failed to connect: ". mysqli_connect_error()); 20 | } 21 | else{ 22 | echo "Connection was successful"; 23 | } 24 | 25 | ?> 26 | -------------------------------------------------------------------------------- /String Functions in Php.php: -------------------------------------------------------------------------------- 1 | "; 5 | echo "the length of "."my string is".strlen($name); 6 | echo"
"; 7 | echo str_word_count($name); 8 | echo"
"; 9 | echo strrev($name); 10 | echo"
"; 11 | $friend= "Tanbir is my best friend"; 12 | 13 | echo strpos($friend,"friend"); 14 | 15 | echo"
"; 16 | 17 | echo str_replace("friend","tanbir",$friend); 18 | 19 | echo"
"; 20 | 21 | echo str_repeat($friend,5); 22 | 23 | echo"
"; 24 | 25 | echo "
";
26 | 
27 | echo"
"; 28 | 29 | echo rtrim(" I am a good boy "); 30 | echo"
"; 31 | 32 | echo ltrim(" I am a good boy "); 33 | echo "
"; 34 | 35 | 36 | 37 | ?> -------------------------------------------------------------------------------- /creating_mysqaldatabase.php: -------------------------------------------------------------------------------- 1 | "; 16 | } 17 | 18 | //create a db 19 | $sql = "CREATE DATABASE Fardin5"; 20 | $result =mysqli_query($conn,$sql); 21 | // check for database creation success 22 | if($result){ 23 | echo "the db created successfully!
"; 24 | } 25 | else { 26 | echo"the db is created successfully because of this error --->". mysqli_error($conn); 27 | } 28 | 29 | ?> -------------------------------------------------------------------------------- /Creating a Table in MySQL using php.php: -------------------------------------------------------------------------------- 1 | "; 16 | } 17 | 18 | //create a table in Database 19 | $sql = "CREATE TABLE `phptrip` ( `sno` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR(12) NOT NULL , `trip` VARCHAR(6) NOT NULL , PRIMARY KEY (`sno`))"; 20 | 21 | $result =mysqli_query($conn,$sql); 22 | // check for the table creation success 23 | if (!$conn){ 24 | die("Sorry we failed to connect: ". mysqli_connect_error()); 25 | } 26 | else{ 27 | echo "Connection was successful"; 28 | } 29 | ?> -------------------------------------------------------------------------------- /delete data.php: -------------------------------------------------------------------------------- 1 | "; 17 | } 18 | 19 | 20 | $sql = "DELETE FROM `phptrip` WHERE `dest` = 'Russia' LIMIT 5"; 21 | $result = mysqli_query($conn, $sql); 22 | $aff = mysqli_affected_rows($conn); 23 | echo "
Number of affected rows: $aff
"; 24 | 25 | if($result){ 26 | echo "Delete successfully"; 27 | } 28 | else{ 29 | $err = mysqli_error($conn); 30 | echo "Not Delete successfully due to this error --> $err"; 31 | } 32 | 33 | ?> 34 | -------------------------------------------------------------------------------- /Functions in Php.php: -------------------------------------------------------------------------------- 1 | "; 4 | 5 | function processMarks($marksArr){ 6 | $sum = 0; 7 | foreach ($marksArr as $value){ 8 | $sum += $value; 9 | } 10 | return $sum; 11 | } 12 | function avgMarks($marksArr){ 13 | $sum = 0; 14 | $l = 1; 15 | foreach ($marksArr as $value){ 16 | $sum += $value; 17 | $l++; 18 | } 19 | return $sum/$l; 20 | } 21 | echo "total marks
"; 22 | 23 | $RohanDas = [34,98,56,58,78,99]; 24 | $sumMark = processMarks($RohanDas); 25 | echo "total mark scored buy Rohan out of 600 is $sumMark
"; 26 | 27 | echo "average marks
"; 28 | 29 | $Tanbir = [99,98,56,100,78,99]; 30 | // $sumMarkTanbir = processMark($Tanbir); 31 | $sumMarksTanbir = avgMarks($Tanbir); 32 | echo "total mark scored buy Tanbir out of 600 is $sumMarksTanbir
"; 33 | 34 | /*for ($i=0; $i -------------------------------------------------------------------------------- /Insert Data Into MySQL.php: -------------------------------------------------------------------------------- 1 | "; 17 | } 18 | 19 | // Variables to be inserted into the table 20 | $name = "Vikrant"; 21 | $destination = "Russia"; 22 | 23 | // Sql query to be executed 24 | $sql = "INSERT INTO `phptrip` (`name`, `dest`) VALUES ('$name', '$destination')"; 25 | $result = mysqli_query($conn, $sql); 26 | 27 | // Add a new trip to the Trip table in the database 28 | if($result){ 29 | echo "The record has been inserted successfully successfully!
"; 30 | } 31 | else{ 32 | echo "The record was not inserted successfully because of this error ---> ". mysqli_error($conn); 33 | } 34 | ?> 35 | -------------------------------------------------------------------------------- /Data Types in Php.php: -------------------------------------------------------------------------------- 1 | "; 32 | echo $income; 33 | echo "
"; 34 | echo $debts; 35 | echo "
"; 36 | 37 | //Boolean - can be either true or false 38 | 39 | $x ="true"; 40 | 41 | $is__friend ="false"; 42 | echo var_dump($x); 43 | echo "
"; 44 | echo var_dump($is__friend); 45 | echo "
"; 46 | 47 | // object - Instances of classes 48 | // emoloyee is a class ---> harry can be one object 49 | // arry - used to store multiple values in a single variable 50 | //array start with 0 no unknown value can give error which is not in arry 51 | 52 | $friend_list =array("Rohan","Tanbir"); 53 | echo var_dump($friend_list); 54 | echo "
"; 55 | echo $friend_list[0]; 56 | echo "
"; 57 | echo $friend_list[1]; 58 | echo "
"; 59 | 60 | //NULL which can reset the value 61 | $name = NULL; 62 | echo var_dump($name); 63 | 64 | 65 | ?> -------------------------------------------------------------------------------- /Selecting and Displaying Data From MySQL.php: -------------------------------------------------------------------------------- 1 | "; 16 | } 17 | $sql = "SELECT * FROM `phptrip`"; 18 | $result = mysqli_query($conn, $sql); 19 | 20 | 21 | //find the no of record 22 | $num = mysqli_num_rows($result); 23 | echo $num; 24 | echo " record in the Database
"; 25 | //display the rows returned by the sql query 26 | if($num> 0){ 27 | /*$row = mysqli_fetch_assoc($result); 28 | echo "
"; 29 | echo var_dump($row); 30 | 31 | $row = mysqli_fetch_assoc($result); 32 | echo "
"; 33 | echo var_dump($row); 34 | 35 | $row = mysqli_fetch_assoc($result); 36 | echo "
"; 37 | echo var_dump($row); 38 | 39 | $row = mysqli_fetch_assoc($result); 40 | echo "
"; 41 | echo var_dump($row);*/ 42 | 43 | //we can fetch in abetter way using the while loop 44 | 45 | while ($row = mysqli_fetch_assoc($result)){ 46 | echo "
"; 47 | // echo var_dump($row); 48 | echo $row['slno'] . " Hello ". $row[ 'name'] . "welcome to ". $row['dest']; 49 | } 50 | } 51 | 52 | ?> -------------------------------------------------------------------------------- /Updating Records in PHP.php: -------------------------------------------------------------------------------- 1 | "; 15 | } 16 | 17 | $sql = "SELECT * FROM `phptrip` WHERE `dest`='Bihar'"; 18 | $result = mysqli_query($conn,$sql); 19 | 20 | //usage of WHERE Clause to fetch database 21 | $num = mysqli_num_rows($result); 22 | $no = 0; 23 | echo $num; 24 | echo " record found in Database
"; 25 | 26 | if($num> 0){ 27 | while($row = mysqli_fetch_assoc($result)){ 28 | echo $no. ". Hello ". $row[ 'name'] ." welcome to" . $row[ 'dest']; 29 | echo "
"; 30 | $no = $no +1; 31 | } 32 | } 33 | 34 | //Usage of WHERE clause to update data 35 | $sql = "UPDATE `phptrip` SET `name` = 'Tanbir 788585' WHERE `dest` = 4"; 36 | //$sql = "UPDATE `phptrip` SET `name` = 'Fromsouth India' WHERE `phptrip`.`slno` = south india"; 37 | // echo var_dump($result); 38 | echo"
"; 39 | $aff = mysqli_affected_rows($conn); 40 | echo "mumber of affected rows:$aff"; 41 | echo "
"; 42 | $result = mysqli_query($conn,$sql); 43 | if($result){ 44 | echo "we updated the record the record successfully"; 45 | } 46 | else{ 47 | echo "we could not update the record successfully"; 48 | } 49 | 50 | ?> -------------------------------------------------------------------------------- /multipledesmensonalarry.php: -------------------------------------------------------------------------------- 1 | "; 4 | // $multiDIm = array(array(2,5,7,8), 5 | // array(1,2,3,1), 6 | // array(4,5,0,1)); 7 | 8 | 9 | $multiDIm = array(array(array(1,5,6,9), 10 | array(8,2,7,1), 11 | array(4,6,7,8), 12 | array(4,6,7,8))); 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | // creating a 2D array 21 | //echo var_dump($multiDIm) 22 | //echo $multiDIm[0][0]; 23 | // echo $multiDIm[1][2]; 24 | 25 | //printing the contents of a 2D array 26 | 27 | 28 | // for ($i=0; $i < count($multiDIm); $i++) { 29 | // echo var_dump($multiDIm); 30 | // echo"
"; 31 | // } 32 | 33 | 34 | // for ($i=0; $i < count($multiDIm); $i++) { 35 | // for($j=0; $j "; 40 | // } 41 | 42 | 43 | for ($i=0; $i < count($multiDIm); $i++) { 44 | for ($j=0; $j "; 51 | } 52 | } 53 | 54 | ?> -------------------------------------------------------------------------------- /Operators in Php.php: -------------------------------------------------------------------------------- 1 | "; 13 | echo "For a + b, the result is".($a+$b); 14 | echo "
"; 15 | echo "For a + b, the result is".($b-$a); 16 | echo "
"; 17 | echo "For a + b, the result is".($a/$b); 18 | echo "
"; 19 | echo "For a + b, the result is".($a%$b); 20 | echo "
"; 21 | echo "For a + b, the result is".($a**$b); 22 | echo "
"; 23 | 24 | // 2.Assignment operators 25 | 26 | $a +=6; 27 | echo "for a,the value is ".$a."
"; 28 | $a *= 5; 29 | echo "for a, the value is ".$a."
"; 30 | $a /= 2; 31 | echo "for a, the value is ".$a."
"; 32 | $a -= 2; 33 | echo "for a, the value is ".$a."
"; 34 | $a %= 2; 35 | echo "for a, the value is ".$a."
"; 36 | 37 | // 3.comparison operator 38 | $f = 7; 39 | $e = 7; 40 | 41 | 42 | echo "For f==e, the result is "; 43 | echo var_dump ($f == $e) . "
"; 44 | echo "For f>e, the result is "; 45 | echo var_dump ($f > $e) . "
"; 46 | // not equal to 47 | echo "For f<>e, the result is "; 48 | echo var_dump ($f <> $e) . "
"; 49 | $z=56; 50 | $y=96; 51 | echo "For z<=y, the result is "; 52 | echo var_dump ($z <= $y) . "
"; 53 | 54 | // logical operator 55 | 56 | $m =true; 57 | $n =False; 58 | 59 | echo "for m and n , the result is"; 60 | echo var_dump($m and $n); 61 | 62 | echo"
"; 63 | // we can write and and or in like this && and || or 64 | 65 | echo "for m and n , the result is"; 66 | echo var_dump($m or $n); 67 | 68 | echo"
"; 69 | 70 | echo "for !m and n , the result is"; 71 | echo var_dump(!$m); 72 | 73 | 74 | 75 | 76 | ?> -------------------------------------------------------------------------------- /indexbootstrap.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Hello, world! 13 | 14 | 15 | 16 |

17 |

56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /get and post form.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | get and post! 12 | 13 | 14 | 15 | 16 | 17 | 18 | 54 | 55 | 60 | success your email '.$email.'and password '.$password.' has been submitted successfully 61 | 62 | '; 63 | } 64 | //submit these to database 65 | 66 | ?> 67 | 68 | 69 | 70 | 71 |
72 |

please enter your email and password

73 |
74 |
75 | 76 | 77 |
We'll never share your email with anyone else.
78 |
79 |
80 | 81 | 82 |
83 | 84 | 85 |
86 |
87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 100 | 101 | -------------------------------------------------------------------------------- /Bootstrap Form and Saving Data.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | get and post! 12 | 13 | 14 | 15 | 16 | 17 | 18 | 54 | 55 | 60 | success your email '.$email.'and password '.$password.' has been submitted successfully 61 | 62 | '; 63 | } 64 | //submit these to database 65 | 66 | ?> 67 | 68 | 69 | 70 | 71 |
72 |

contact us for your consul

73 |
74 |
75 | 76 | 77 |
We'll never share your email with anyone else.
78 |
79 | 80 |
81 | 82 | 83 |
We'll never share your email with anyone else.
84 |
85 | 86 |
87 | 88 | 89 | 90 |
91 | 92 | 93 |
94 |
95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 108 | 109 | -------------------------------------------------------------------------------- /fetch.php: -------------------------------------------------------------------------------- 1 | 12 | Then, create index.php 13 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | Document 29 | 38 | 39 | 40 |
41 |
42 |

Delhi Restaurent & Motel

43 |
Shine Metro Mkadi Naka (New - Delhi)
44 |
45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 71 | 74 | 77 | 78 | 79 | 80 |
No.Meal ItemsQtyPrice
1 59 | 70 | 72 | 73 | 75 |

76 |
81 | 84 |
85 |
86 |
87 |
88 |

Receipt

89 |
90 | Time : 91 |
92 |
93 | : 94 |
95 |
96 |

Order No:

97 |
98 |
99 |
100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 122 | 126 | 127 | 128 | 129 | 130 | 131 | 134 | 138 | 139 |
No.Product NameQuantityPriceTotal
119 |
Sub Total: ₹
120 |

Tax (5%) : ₹

121 |
123 |
124 |
125 |
132 |
Gross Total: ₹
133 |
135 |
136 | 137 |
140 |
141 |
142 |
143 |
144 |
145 | 146 | 147 | 249 | 250 | 251 | --------------------------------------------------------------------------------