Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dbconn.php
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "sca";
- $conn = new mysqli($servername, $username, $password, $dbname);
- if ($conn->connect_error)
- {
- die("Connection failed: " . $conn->connect_error);
- }
- ?>
- ----------------------------------------------
- Index.php
- <html>
- <head>
- <title>Couse List</title>
- </head>
- <body bgcolor="lightgreen">
- <center><a href="new_course.php">New Course</a></center>
- <table align="center" border="1" cellspacing="2" cellpadding="2">
- <caption><h2>Course List</h2></caption>
- <tr>
- <td>S.L. No.</td>
- <td>Courses Name</td>
- <td>Delete</td>
- </tr>
- <?php
- error_reporting(0);
- include("dbconn.php");
- $res = mysqli_query ($conn,"Select * from courses");
- while($row=mysqli_fetch_array($res))
- {
- ?>
- <tr>
- <td><?php echo $row['id'];?></td>
- <td><?php echo $row['name'];?></td>
- <td><a href="delete_course.php?id=<?php echo $row['id']?>">Delete</a></td>
- </tr>
- <? } ?>
- </table>
- </body>
- </html>
- ----------------------------------------------
- new_course.php
- <html>
- <head>
- <title>Add New Course</title>
- </head>
- <body bgcolor="#0033FF">
- <center><a href="index.php">Course List</a></center>
- <center>
- <form method="post" action="action.php">
- <table border="1" cellpadding="2" cellspacing="2">
- <caption><marquee><h2>Add New Course</h2></marquee></caption>
- <tr>
- <th>Course Name</th>
- <td><input type="text" name="name"/> </td>
- </tr>
- </table>
- <br><br>
- <input type="submit" name="submit" value="SUBMIT">
- <input type="reset" name="reset" value="RESET">
- </form>
- </center>
- </body>
- </html>
- ----------------------------------------------
- action.php
- <?php
- error_reporting(0);
- include("dbconn.php");
- $name = $_POST['name'];
- $sql = "INSERT INTO courses(name) VALUES('$name')";
- mysqli_query($conn, $sql);
- echo "Inserted Successfully<br/>";
- header("location:index.php");
- ?>
- ----------------------------------------------
- delete_course.php
- <?php
- error_reporting(0);
- include("dbconn.php");
- $id = $_REQUEST['id'];
- mysqli_query($conn,"Delete from courses where id='$id'");
- header("location:index.php");
- ?>
- ----------------------------------------------
- update_user.php
- <?php
- error_reporting(0);
- include("dbconn.php");
- $u_id = $_POST['u_id'];
- $u_name = $_POST['u_name'];
- $u_email = $_POST['u_email'];
- $u_ph = $_POST['u_ph'];
- $u_address = $_POST['u_address'];
- $sql = "UPDATE users SET u_name = '$u_name', u_email = '$u_email', u_ph = '$u_ph', u_address = '$u_address' WHERE u_id = '$u_id'";
- //mysql_query($sql);
- mysqli_query($conn,$sql);
- header("location:user_list.php");
- ?>
- ----------------------------------------------
- edit_user.php
- <?php
- error_reporting(0);
- include("dbconn.php");
- $u_id = $_REQUEST['id'];
- $sql = "Select * from users where u_id = '$u_id'";
- //$res = mysql_query($sql);
- $res = mysqli_query($conn,$sql);
- //$row = mysql_fetch_array($res);
- $row = mysqli_fetch_array($res);
- ?>
- <html>
- <body>
- <form method="POST" action="update_user.php">
- <table align="center">
- <caption><h2>Update User</h2></caption>
- <tr>
- <td>User Name</td>
- <td><input type="text" name="u_name" value="<?php echo $row['u_name'];?>"></td>
- </tr>
- <tr>
- <td>E-mail</td>
- <td><input type="text" name="u_email" value="<?php echo $row['u_email'];?>"></td>
- </tr>
- <tr>
- <td>Phone</td>
- <td><input type="text" name="u_ph" value="<?php echo $row['u_ph'];?>"></td>
- </tr>
- <tr>
- <td>Address</td>
- <td>
- <input type="text" name="u_address" value="<?php echo $row['u_address'];?>">
- <input type="hidden" name="u_id" value="<?php echo $row['u_id'];?>">
- </td>
- </tr>
- <tr>
- <td colspan="2"><button>Update</button></td>
- </tr>
- </table>
- </form>
- </body>
- </html>
- -----------------------------------------
- Index.php
- <html>
- <body bgcolor="#6699FF">
- <center>
- <table>
- <caption><marquee>Sceond CAP</marquee></caption>
- <br>
- <br>
- <tr bgcolor="#00FF66" ><br>
- <td><a href='string.php'> String Reverse</a></td>
- <td><a href='function.php'> Gobal Variables<a/></td>
- </tr>
- </table>
- </center>
- </body>
- </html>
- -----------------------------------------
- string.php
- <html>
- <body>
- <center>
- The String is Hello
- <br>
- <br>
- Using strlen Function
- <br>
- <?php
- $string = 'Hello';
- for ($i=0; $i < strlen($string); $i++)
- {
- printf("The %dth character is %s<br>",
- $i, $string{$i});
- }
- ?>
- <br>
- <br>
- Using strrrev Function<br>
- <?php
- $reverse=strrev($string);
- for($i=0;$i<strlen($string);$i++)
- {
- echo "the ",$i,"th character is ",substr($reverse,$i,1),"<br>";
- }
- ?>
- <br>
- <a href="index.php">Back</a>
- </center>
- </body>
- </html>
- -----------------------------------------
- function.php
- <html>
- <body>
- <center>
- <br>
- <br>
- <br>
- <?php
- $a = 3;
- echo 'Initially the value of $a is 3<br>';
- function tahsin()
- {
- global $a;
- $a += 2;
- }
- tahsin();
- echo 'After using the global functionality, the value of $a is ' .$a;
- ?>
- <br>
- <br>
- <a href="index.php">Back</a>
- </center>
- </body>
- </html>
- -----------------------------------------
- PHP Operators:
- Arithmetic operators
- Assignment operators
- Comparison operators
- Increment/Decrement operators
- Logical operators
- String operators
- Array operators
- ----------------------------------------
- PHP - The if...elseif....else Statement
- <?php
- $t = date("H");
- if ($t < "10") {
- echo "Have a good morning!";
- } elseif ($t < "20") {
- echo "Have a good day!";
- } else {
- echo "Have a good night!";
- }
- ?>
- --------------------------------------
- PHP switch Statement
- <?php
- $favcolor = "red";
- switch ($favcolor) {
- case "red":
- echo "Your favorite color is red!";
- break;
- case "blue":
- echo "Your favorite color is blue!";
- break;
- case "green":
- echo "Your favorite color is green!";
- break;
- default:
- echo "Your favorite color is neither red, blue, nor green!";
- }
- ?>
- ---------------------------------------
- PHP while Loop
- <?php
- $x = 1;
- while($x <= 5) {
- echo "The number is: $x <br>";
- $x++;
- }
- ?>
- -------------------------------------
- PHP foreach Loop
- <?php
- for ($x = 0; $x <= 10; $x++) {
- echo "The number is: $x <br>";
- }
- ?>
- -----------------------------------
- Arrays
- <?php
- $cars = array("Volvo", "BMW", "Toyota");
- echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
- ?>
- ------------------------------
- Cookies
- <?php
- $cookie_name = "user";
- $cookie_value = "John Doe";
- setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
- ?>
- <html>
- <body>
- <?php
- if(!isset($_COOKIE[$cookie_name])) {
- echo "Cookie named '" . $cookie_name . "' is not set!";
- } else {
- echo "Cookie '" . $cookie_name . "' is set!<br>";
- echo "Value is: " . $_COOKIE[$cookie_name];
- }
- ?>
- </body>
- </html>
- --------------------------------
- session
- <?php
- // Start the session
- session_start();
- ?>
- <!DOCTYPE html>
- <html>
- <body>
- <?php
- // Set session variables
- $_SESSION["favcolor"] = "green";
- $_SESSION["favanimal"] = "cat";
- echo "Session variables are set.";
- ?>
- </body>
- </html>
- -----------------------------
- date time
- <?php
- echo "Today is " . date("Y/m/d") . "<br>";
- echo "Today is " . date("Y.m.d") . "<br>";
- echo "Today is " . date("Y-m-d") . "<br>";
- echo "Today is " . date("l");
- ?>
- ---------------------------
- switch
- <?php
- $favcolor="pink";
- switch($favcolor){
- case"red":
- echo"Your favorite coloris red!";
- break;
- case"pink":
- echo"Your favorite coloris pink!";
- break;
- case"green":
- echo"Your favorite coloris green!";
- break;
- default:
- echo"Your favorite coloris neither red, blue, nor green!";}
- ?>
- ------------------------------------
- Image eclipse
- <?php
- $image = imagecreatetruecolor(150, 150);
- //imagecreatetruecolor(width, height)
- $white = imagecolorallocate($image, 255, 255, 255);
- $text_color = imagecolorallocate($image,0,255,0);
- imagefilledrectangle($image, 0, 0, 150, 150, $white);
- $color = imagecolorallocatealpha($image, 0, 0, 255, 30);
- //imagecolorallocatealpha(image, red, green, blue, alpha)
- //The alpha value is between 0 (opaque) and 127 (transparent).
- imagefilledellipse($image, 75, 75, 80, 63, $color);
- imagestring($image,5,10,110,"Eclipse Created",$text_color);
- header("Content-Type: image/png");
- imagepng($image);
- ?>
- ----------------------------------
- <?php
- $image = imagecreate(200, 200);
- $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
- $black = imagecolorallocate($image, 0x00, 0x00, 0x00);
- $color = imagecolorallocate($image, 255,0,255);
- $color1 = imagecolorallocate($image,0,0,255);
- $color2 = imagecolorallocate($image,255,0,0);
- //imagestring(image, font_id, x, y, text, color);
- imagestring($image, 1, 10, 10, "LPU Practical", $black);
- imagestring($image, 2, 10, 30, "Happy", $black);
- imagestring($image, 3, 10, 50, "Childrens", $color);
- imagestring($image, 4, 10, 70, "Day", $color1);
- imagestring($image, 5, 10, 90, "Have a good day", $color2);
- header("Content-Type: image/png");
- imagepng($image);
- ?>
- ----------------------------------------
- <?php
- $image = imagecreatetruecolor(150, 150);
- $white = imagecolorallocate($image, 255, 255, 255);
- imagefilledrectangle($image, 0, 0, 150, 150, $white);
- $red = imagecolorallocatealpha($image, 255, 50, 0, 36);
- //imagecolorallocatealpha(image, red, green, blue, alpha)
- imagefilledellipse($image, 75, 75, 80, 50, $red);
- $gray = imagecolorallocatealpha($image, 70, 70, 70, 5);
- //imagecolorallocatealpha(image, red, green, blue, alpha)
- imagefilledrectangle($image, 60, 60, 120, 120, $gray);
- header("Content-Type: image/png");
- imagepng($image);
- ?>
- -----------------------------------------
- <?php
- $image = imagecreate(200, 200);
- $white = imagecolorallocate($image, 255, 255, 255);
- //$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
- $black = imagecolorallocate($image, 0, 0, 0);
- //$black = imagecolorallocate($image, 0x00, 0x00, 0x00);
- imagefilledrectangle($image, 80, 50, 500, 300, $black);
- header("Content-Type: image/png");
- imagepng($image);
- ?>
- --------------------------------------
Add Comment
Please, Sign In to add comment