Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore CU-BCA-SEM-V-Web Development Using Php Practical-Web Technologies Practical-Second Draft

CU-BCA-SEM-V-Web Development Using Php Practical-Web Technologies Practical-Second Draft

Published by Teamlease Edtech Ltd (Amita Chitroda), 2022-02-26 02:07:45

Description: CU-BCA-SEM-V-Web Development Using Php Practical-Web Technologies Practical-Second Draft

Search

Read the Text Version

WEB DEVELOPMENT USING PHP PRACTICAL / WEB TECHNOLOGIES PRACTICAL Course Code: BCA157/BCA604 Credits: 1/6 Course Objectives  This course is designed to provide a comprehensive introduction to computer graphics techniques.  The course will make the students able to carry out computer graphics and to evaluate software and hardware for that use. The course is a foundation for a master´s thesis within computer graphics.  Provide an understanding of mapping from a world coordinates to device coordinates, clipping. EXPERIMENT 1-CREATING SIMPLE WEBPAGE USING PHP. Solution <?php /* Create simple Website with PHP - // create an array with data for title, and meta, for each page $pgdata = array();

$pgdata['index'] = array( 'title'=>'Title for Home page', 'description'=>'Here add the description for Home page', 'keywords'=>'meta keywords, for, home page' ); $pgdata['about_me'] = array( 'title'=>'Title for About Me page', 'description'=>'Description for About Me, https://coursesweb.net', 'keywords'=>'about me, https://coursesweb.net' ); $pgdata['images'] = array( 'title'=>'Title for Images', 'description'=>'Here add the description for the page with images', 'keywords'=>'images, pictures, photo' ); // set the page name $pgname = isset($_GET['pg']) ? trim(strip_tags($_GET['pg'])) : 'index'; // get title, and meta data for current /accessed page $title = $pgdata[$pgname]['title']; $description = $pgdata[$pgname]['description'];

$keywords = $pgdata[$pgname]['keywords']; // set header for utf-8 encode header('Content-type: text/html; charset=utf-8'); ?> <!doctype html> <html> <head> <meta charset=\"utf-8\" /> <title><?php echo $title; ?></title> <meta name=\"description\" content=\"<?php echo $description; ?>\" /> <meta name=\"keywords\" content=\"<?php echo $keywords; ?>\" /> <!--[if IE]><script src=\"http://html5shiv.googlecode.com/svn/trunk/html5.js\"></script><![endif] --> <style><!-- body { margin:0; text-align:center; padding:0 1em; } header, footer, section, aside, nav, article { display: block; } #posts{

position:relative; width:99%; margin:0.5em auto; background:#fdfefe; } #menu { float:left; width:15em; margin:0 auto; background:#f8f9fe; border:1px solid blue; text-align:left; } #menu li a:hover { text-decoration:none; color:#01da02; } #article { margin:0 1em 0 16em; background:#efeffe; border:1px solid #01da02; padding:0.2em 0.4em;

} #footer { clear:both; position:relative; background:#edfeed; border:1px solid #dada01; width:99%; margin:2em auto 0.5em auto; } --></style> </head> <body> <header id=\"header\"> <h1><?php echo $title; ?></h1> </header> <section id=\"posts\"> <nav id=\"menu\"> <ul> <li><a href=\"new 1.php\" title=\"Home page\">Home</a></li> <li><a href=\"new 1.php?pg=about_me\" title=\"About Me\">About Me</a></li>

<li><a href=\"new 1.php?pg=images\" title=\"Images\">Images</a></li> </ul> </nav> <article id=\"article\"><?php echo file_get_contents('pages/'. $pgname. '.htm'); ?></article> </section> <footer id=\"footer\"> <p>From: <a href=\"https://coursesweb.net/php-mysql/\" title=\"Free PHP-MySQL course\">PHP-MySQL Course</a></p> </footer> </body> </html> Output



EXPERIMENT 2-USE OF CONDITIONAL STATEMENTS IN PHP. Solution The if Statement Syntax if (condition) { code to be executed if condition is true; } Program <!DOCTYPE html> <html> <body> <?php $t = date(\"H\"); if ($t < \"20\") { echo \"Have a good day!\"; }

?> </body> </html> Output Have a good day! The if...else Statement Syntax if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; } Program <!DOCTYPE html> <html> <body> <?php $t = date(\"H\"); if ($t < \"20\") {

echo \"Have a good day!\"; } else { echo \"Have a good night!\"; } ?> </body> </html> Output Have a good day! The if...elseif...else Statement Syntax if (condition) { code to be executed if this condition is true; } elseif (condition) { code to be executed if first condition is false and this condition is true; } else { code to be executed if all conditions are false; } Program <?php

$marks=69; if ($marks<33){ echo \"fail\"; } else if ($marks>=34 && $marks<50) { echo \"D grade\"; } else if ($marks>=50 && $marks<65) { echo \"C grade\"; } else if ($marks>=65 && $marks<80) { echo \"B grade\"; } else if ($marks>=80 && $marks<90) { echo \"A grade\"; } else if ($marks>=90 && $marks<100) { echo \"A+ grade\"; } else { echo \"Invalid input\"; }

?> Output

EXPERIMENT 3-USE OF LOOPING STATEMENT IN PHP. Solution The for loop statement Syntax for (initialization; condition; increment){ code to be executed; } Program <html> <body> <?php $a = 0; $b = 0; for( $i = 0; $i<5; $i++ ) { $a += 10; $b += 5; } echo (\"At the end of the loop a = $a and b = $b\" ); ?> </body> </html> Output At the end of the loop a = 50 and b = 25

The while loop statement Syntax while (condition) { code to be executed; } Program <html> <body> <?php $i = 0; $num = 50; while( $i < 10) { $num--; $i++; } echo (\"Loop stopped at i = $i and num = $num\" ); ?> </body> </html> Output Loop stopped at i = 10 and num = 40 The do...while loop statement Syntax do { code to be executed; } while (condition);

Program <html> <body> <?php $i = 0; $num = 0; do { $i++; } while( $i < 10 ); echo (\"Loop stopped at i = $i\" ); ?> </body> </html> Output Loop stopped at i = 10 The foreach loop statement Syntax foreach (array as value) { code to be executed; } Program <html> <body>

<?php $array = array( 1, 2, 3, 4, 5); foreach( $array as $value ) { echo \"Value is $value <br />\"; } ?> </body> </html> Output Value is 1 Value is 2 Value is 3 Value is 4 Value is 5

EXPERIMENT 4-CREATING DIFFERENT TYPES OF ARRAYS. Solution There are three types of arrays that you can create. These are:  Indexed array — An array with a numeric key.  Associative array — An array where each key has its own specific value.  Multidimensional array — An array containing one or more arrays within itself. Indexed Arrays Program <!DOCTYPE html> <html lang=\"en\"> <head> <title>PHP Indexed Arrays</title> </head> <body> <?php $colors = array(\"Red\", \"Green\", \"Blue\");

// Printing array structure print_r($colors); ?> </body> </html> Output Array ( [0] => Red [1] => Green [2] => Blue ) Associative Arrays Program <!DOCTYPE html> <html lang=\"en\"> <head> <title>PHP Associative Array</title> </head> <body> <?php $ages = array(\"Peter\"=>22, \"Clark\"=>32, \"John\"=>28);

// Printing array structure print_r($ages); ?> </body> </html> Output Array ( [Peter] => 22 [Clark] => 32 [John] => 28 ) Multidimensional Arrays Program <!DOCTYPE html> <html lang=\"en\"> <head> <title>PHP Multidimensional Array</title> </head> <body> <?php // Define nested array

$contacts = array( array( \"name\" => \"Peter Parker\", \"email\" => \"peterparker@mail.com\", ), array( \"name\" => \"Clark Kent\", \"email\" => \"clarkkent@mail.com\", ), array( \"name\" => \"Harry Potter\", \"email\" => \"harrypotter@mail.com\", ) ); // Access nested value echo \"Peter Parker's Email-id is: \" . $contacts[0][\"email\"]; ?> </body> </html> Output Peter Parker's Email-id is: peterparker@mail.com

EXPERIMENT 5-USAGE OF ARRAY FUNCTIONS. Solution Below we have a list of some commonly used array functions and its usage in PHP: sizeof($arr) This function returns the size of the array or the number of data elements stored in the array. Program <?php $lamborghinis = array(\"Urus\", \"Huracan\", \"Aventador\"); echo \"Size of the array is: \". sizeof($lamborghinis); ?> Output Size of the array is: 3 is_array($arr) To check whether the provided data is in form of an array, we can use the is_array() function. It returns True if the variable is an array and returns False otherwise. Program <?php $lamborghinis = array(\"Urus\", \"Huracan\", \"Aventador\"); // using ternary operator echo is_array($lamborghinis) ? 'Array' : 'not an Array'; $mycar = \"Urus\"; // using ternary operator echo is_array($mycar) ? 'Array' : 'not an Array'; ?> Output Array

not an Array in_array($var, $arr) When using an array, we may often want to check whether a certain value is present in the array or not. Program <?php $lamborghinis = array(\"Urus\", \"Huracan\", \"Aventador\"); // new concept car by lamborghini $concept = \"estoque\"; echo in_array($concept, $lamborghinis) ? 'Added to the Lineup' : 'Not yet!' ?> Output Not yet! As we can see unlike the other functions above, this one takes two arguments, one is the value to be searched in the array, and the second one is the array itself. print_r($arr) we can use this function to print the array in the most descriptive way possible. This function prints the complete representation of the array, along with all the keys and values. Program <?php $lamborghinis = array(\"Urus\", \"Huracan\", \"Aventador\"); print_r($lamborghinis); ?> Output Array ( [0] => \"Urus\" [1] => \"Huracan\" [2] => \"Aventador\" )

array_merge($arr1, $arr2) If you want to combine two different arrays into a single array, you can do so using this function. Program <?php $hatchbacks = array( \"Suzuki\" => \"Baleno\", \"Skoda\" => \"Fabia\", \"Hyundai\" => \"i20\", \"Tata\" => \"Tigor\" ); // friends who own the above cars $friends = array(\"Vinod\", \"Javed\", \"Navjot\", \"Samuel\"); // let's merge the two arrays into one $merged = array_merge($hatchbacks, $friends); print_r($merged); ?> Output Array ( [Suzuki] => Baleno [Skoda] => Fabia [Hyundai] => i20 [Tata] => Tigor [0] => Vinod [1] => Javed [2] => Navjot [3] => Samuel ) array_values($arr) In an array, data is stored in form of key-value pairs, where key can be numerical(in case of indexed array) or user-defined strings(in case of

associative array) and values. If we want to take all the values from our array, without the keys, and store them in a separate array, then we can use array_values() function. Program <?php $hatchbacks = array( \"Suzuki\" => \"Baleno\", \"Skoda\" => \"Fabia\", \"Hyundai\" => \"i20\", \"Tata\" => \"Tigor\" ); // friends who own the above cars $friends = array(\"Vinod\", \"Javed\", \"Navjot\", \"Samuel\"); // let's merge the two arrays into one $merged = array_merge($hatchbacks, $friends); //getting only the values $merged = array_values($merged); print_r($merged); ?> Output Array ( [0] => Baleno [1] => Fabia [2] => i20 [3] => Tigor [4] => Vinod [5] => Javed [6] => Navjot [7] => Samuel ) array_keys($arr)

Just like values, we can also extract just the keys from an array. Program <?php //getting only the keys $keys = array_values($merged); print_r($keys); ?> Output Array ( [0] => Suzuki [1] => Skoda [2] => Hyundai [3] => Tata [4] => 0 [5] => 1 [6] => 2 [7] => 3 ) array_pop($arr) This function removes the last element of the array. Hence it can be used to remove one element from the end. Program <?php $lamborghinis = array(\"Urus\", \"Huracan\", \"Aventador\"); // removing the last element array_pop($lamborghinis); print_r($lamborghinis); ?> Output Array ( [0] => Urus

[1] => Huracan ) array_push($arr, $val) This function is the opposite of the array_pop() function. This can be used to add a new element at the end of the array. Program <?php $lamborghinis = array(\"Urus\", \"Huracan\", \"Aventador\"); // adding a new element at the end array_push($lamborghinis, \"Estoque\"); print_r($lamborghinis); ?> Output Array ( [0] => Urus [1] => Huracan [2] => Aventador [3] => Estoque ) array_shift($arr) This function can be used to remove/shift the first element out of the array. Program <?php $lamborghinis = array(\"Urus\", \"Huracan\", \"Aventador\"); // removing the first element array_shift($lamborghinis); print_r($lamborghinis); ?> Output Array ( [0] => Huracan

[1] => Aventador ) Similar to this, we have another function array_unshift($arr, $val) to add a new value($val) at the start of the array(as the first element). sort($arr) This function sorts the array elements in ascending order. In case of a string value array, values are sorted in ascending alphabetical order. Program <?php $lamborghinis = array(\"Urus\", \"Huracan\", \"Aventador\", \"Estoque\"); // sort the array sort($lamborghinis); print_r($lamborghinis); ?> Output Array ( [0] => Aventador [1] => Estoque [2] => Huracan [3] => Urus ) array_map('function_name', $arr) If you want to perform certain operation on all the values stored in an array, you can use the function array_map(). Program <?php function addOne($val) { // adding 1 to input value return ($val + 1); } $numbers = array(10, 20, 30, 40, 50);

// using array_map to operate on all the values stored in array $numbers = array_map('addOne', $numbers); print_r($numbers) ?> Output Array ( [0] => 11 [1] => 21 [2] => 31 [3] => 41 [4] => 51 ) The function array_walk($arr, 'function_name') works just like the array_map() function. array_flip($arr) This function interchange the keys and the values of a PHP associative array. Program <?php $hatchbacks = array( \"Suzuki\" => \"Baleno\", \"Skoda\" => \"Fabia\", \"Hyundai\" => \"i20\", \"Tata\" => \"Tigor\" ); // we can directly print the result of array flipping print_r(array_flip($hatchbacks)); ?> Output Array ( [Baleno] => Suzuki [Fabia] => Skoda [i20] => Hyundai

[Tigor] => Tata ) array_reverse($arr) This function is used to reverse the order of elements, making the first element last and last element first, and similarly rearranging other array elements. Program <?php $num = array(10, 20, 30, 40, 50); // printing the array after reversing it print_r(array_reverse($num)); ?> Output Array ( [0] => 50 [1] => 40 [2] => 30 [3] => 20 [4] => 10 ) array_rand($arr) If you want to pick random data element from an array, you can use the array_rand() function. This function randomly selects one element from the given array and returns it. Program <?php $colors = array(\"red\", \"black\", \"blue\", \"green\", \"white\", \"yellow\"); echo \"Color of the day: \". $colors[array_rand($colors)]; ?> Output Color of the day: green Every time you run the above script, it will return a random color value from

the array. array_slice($arr, $offset, $length) This function is used to create a subset of any array. Using this function, we define the starting point($offset, which is the array index from where the subset starts) and the length(or, the number of elements required in the subset, starting from the offset). Program <?php $colors = array(\"red\", \"black\", \"blue\", \"green\", \"white\", \"yellow\"); print_r(array_slice($colors, 2, 3)); ?> Output Array ( [0] => blue [1] => green [2] => white )

EXPERIMENT 6-CREATING USER DEFINED FUNCTIONS. Solution Syntax //define a function function myfunction($arg1, $arg2, ... $argn) { statement1; statement2; .. .. return $val; } //call function $ret=myfunction($arg1, $arg2, ... $argn); user defined function Example In following example shows definition and call to a usr defined function sayhello() Program <?php //function definition function sayHello(){ echo \"Hello World!\"; } //function call sayHello(); ?> Output Hello World!

function with arguments In following example, a function is defined with two formal arguments Program <?php function add($arg1, $arg2){ echo $arg1+$arg2 . \"\\n\"; } add(10,20); add(\"Hello\", \"World\"); ?> Output 30 function return User defined function in following example processes the provided arguments and retuns a value to calling environment Program <?php function add($arg1, $arg2){ return $arg1+$arg2; } $val=add(10,20); echo \"addition:\". $val. \"\\n\"; $val=add(\"10\",\"20\"); echo \"addition: $val\"; ?> Output addition:30 addition:30 function with default argument value While defining a function , a default value of argument may be assigned. If value is not assigned to such agument while calling the function, this default will be used for processing inside function. In following example, a function is defined with argument having default value

Program <?php function welcome($user=\"Guest\"){ echo \"Hello $user\\n\"; } //overrides default welcome(\"admin\"); //uses default welcome(); ?> Output Hello admin Hello Guest function with variable number of arguments It is possible to define a function with ability to receive variable number of arguments. The name of formal argument in function definition is prefixed by ... token. Following example has add() function that adds a list of numbers given as argument Program <?php function add(...$numbers){ $ttl=0; foreach ($numbers as $num){ $ttl=$ttl+$num; } return $ttl; } $total=add(10,15,20); echo \"total= $total\\n\"; echo \"total=\". add(1,2,3,4,5). \"\\n\"; ?> Output total= 45

total=15 It is also possible to obtain a list of arguments passed to a function with the help offunc_get_args() function. We can run a PHP loop to traverse each value in the list of arguments passed. In that case the function definition doesn't have a formal argument. Program <?php function add(){ $numbers=func_get_args(); $ttl=0; foreach ($numbers as $num){ $ttl=$ttl+$num; } return $ttl; } $total=add(10,15,20); echo \"total= $total\\n\"; echo \"total=\". add(1,2,3,4,5). \"\\n\"; ?> Output total= 45 total=15 function within another function A function may be defined inside another function's body block. However, inner function can not be called before outer function has been invoked. Program <?php function hello(){ echo \"Hello\\n\"; function welcome(){ echo \"Welcome to TP\\n\"; } }

//welcome(); hello(); welcome(); ?> Output Comment the line and run again Hello Welcome to TP Recursive function A function that calls itself is called recursive function. Calling itself unconditionally creates infinite loop and results in out of memory error because of stack full. Following program calls factorial() function recursively Program <?php function factorial($n){ if ($n < 2) { return 1; } else { return ($n * factorial($n-1)); } } echo \"factorial(5) = \". factorial(5); ?> Output factorial(5) = 120

EXPERIMENT 7-CREATING SIMPLE APPLICATIONS USING PHP. Solution Creating a simple login system using PHP without any database. This system can be use to protect multiple files and allow only logged in users access. Program Create Index.php <!DOCTYPE html> <html lang=\"en\"> <head> <!-- Title --> <title>Login Page </title> <style> label { width: 100%; max-width: 100px; display: inline-block; text-align: right; } div { margin-top: 1em; } </style> </head>

<body> <form action=\"auth/login.php\" method=\"post\"> <div> <h2>Simple Login Script Demo</h2> </div> <div> <label>Email</label> <input type=\"text\" name=\"email\"> </div> <div> <label>Password</label> <input type=\"password\" name=\"password\"> </div> <div> <input type='submit' value=\"Login\" style=\"margin-left: 105px;\"> </div> <input type=\"hidden\" name=\"submitted\" value=\"1\"> </form> <p></p> <p>Email: test@example.com</p> <p>Password: bulldog19</p> </body> </html> Login.php <?php if ( ! isset( $_POST['submitted'] ) ) header('Location: ' . $_SERVER['HTTP_REFERER']);

$credentials = [ 'email' => 'test@example.com', 'password' => 'bulldog19' ]; if ( $credentials['email'] !== $_POST['email'] OR $credentials['password'] !== $_POST['password'] ) { header('Location: ' . $_SERVER['HTTP_REFERER']); exit(); } session_start(); // Storing session data $_SESSION[\"isLogged\"] = \"1\"; header('Location:' . '../home.php'); exit(); sessman.php <?php session_start(); if ( ! isset( $_SESSION['isLogged'] ) or \"1\" != $_SESSION['isLogged'] ) header('Location: ' . '../index.php'); ?> logout.php <?php

session_start(); if ( isset( $_SESSION['isLogged'] ) ) unset( $_SESSION['isLogged'] ); session_destroy(); header('Location:' . '../index.php'); home.php <?php require_once 'auth/sessman.php'; // remove this after testing is over ?> <!DOCTYPE html> <html lang=\"en\"> <head></head> <body> <p>Welcome to home page</p> <p><a href=\"auth/logout.php\">Logout</a> </body> </html> Output

After entering email and password After clicking Logout back to first screen.

EXPERIMENT 8-CREATING SIMPLE TABLE WITH CONSTRAINTS. Solution The CREATE TABLE statement is used to create a table in MySQL. Syntax Here is a generic SQL syntax to create a MySQL table − CREATE TABLE table_name (column_name column_type); We will create a table named \"MyGuests\", with five columns: \"id\", \"firstname\", \"lastname\", \"email\" and \"reg_date\": CREATE TABLE MyGuests ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, email VARCHAR(50), reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) Program <?php $servername = \"127.0.0.1\"; $username = \"root\"; $password = \"\"; $dbname = \"db\"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die(\"Connection failed: \" . $conn->connect_error);

} // sql to create table $sql = \"CREATE TABLE MyGuests1 ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, email VARCHAR(50), reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP )\"; if ($conn->query($sql) === TRUE) { echo \"Table MyGuests created successfully\"; } else { echo \"Error creating table: \" . $conn->error; } $conn->close(); ?> Output

EXPERIMENT 9-INSERTION, UPDATING AND DELETION OF ROWS IN MYSQL TABLES. Solution Syntax In MySQL INSERT INTO statement syntax is :- INSERT INTO table_name ( field1, field2,…fieldN ) VALUES ( value1, value2,…valueN ); Syntax In MySQL UPDATE statement syntax is :- UPDATE table_name SET field1=new-value1, field2=new-value2 [WHERE Clause] Syntax In MySQL DELETE statement syntax is :- DELETE FROM table_name; OR DELETE FROM table_name [WHERE Clause]; Program CREATE DATABASE School; USE School;

CREATE TABLE Students ( StudentId INT PRIMARY KEY, FirstName VARCHAR(50), LastName VARCHAR(50), Class VARCHAR(50), Age INT ); Insert, Update, Delete using SQL Script in MySQL INSERT INTO students (StudentId, FirstName, LastName, Class, Age) VALUES (3, 'Hina', 'Sharma', 'First', 18); INSERT INTO students (StudentId, FirstName, LastName, Class, Age) VALUES (4, 'Rakesh', 'Sahoo', 'Second', 17); Now, we want to update the FirstName of the Student whose Id is 3 and LastName of the Student whose Id is 4. Then the following Update SQL Script will update the same in the Students table. UPDATE students SET `FirstName` = 'Suresh' WHERE (`StudentId` = '3'); UPDATE students SET `LastName` = 'Mohanty' WHERE (`StudentId` = '4');

Now, we want to delete the student whose IDs are 3 and 4. Then the following DELETE SQL Script will delete the same from the Students table. DELETE FROM students WHERE (`StudentId` = '3'); DELETE FROM students WHERE (`StudentId` = '4');

Display records Select * from students;



EXPERIMENT 10-SEARCHING OF DATA BY DIFFERENT CRITERIA. Solution Program CREATE TABLE user ( first_name VARCHAR(50), last_name VARCHAR(50), birth_date DATE, articles_count INT(3) ); Test data Before trying our queries, it's always a good idea to have some test data to work with so we don't have just our 4 users. Let's insert some entries to our user table to work with. I've prepared something for you. First, empty your table (so we have the same data): DELETE FROM `user`; Next, run the following SQL query: INSERT INTO `user` ( `first_name`, `last_name`, `birth_date`, `articles_count` ) VALUES ('John', 'Smith', '1984-11-03', 17), ('Steven', 'Murphy', '1942-10-17', 12), ('George', 'Lam', '1958-7-10', 5), ('Linda', 'Martin', '1935-5-15', 6), ('Donald', 'Brown', '1967-4-17', 2),

('Aron', 'Heaven', '1995-2-20', 1), ('Paul', 'Lee', '1984-4-18', 1), ('David', 'Clark', '1973-5-14', 3), ('Mark', 'Wilson', '1969-6-2', 7), ('Sarah', 'Johnson', '1962-7-3', 8), ('Charles', 'Lopez', '1974-9-10', 0), ('Jennifer', 'Williams', '1976-10-2', 1), ('Daniel', 'Jones', '1948-11-3', 1), ('Betty', 'Miller', '1947-5-9', 1), ('Michelle', 'Davis', '1956-3-7', 0), ('Mary', 'Taylor', '1954-2-11', 5), ('Barbara', 'Thomas', '1978-1-21', 3), ('Donna', 'Johnson', '1949-7-26', 12), ('Joseph', 'Murphy', '1973-7-28', 4), ('Helen', 'Murphy', '1980-8-11', 8), ('Jeff', 'Moore', '1982-9-30', 18), ('Anthony', 'Jackson', '1961-1-15', 2), ('Nancy', 'Thompson', '1950-8-29', 4), ('Edward', 'White', '1974-2-26', 5), ('Lucy', 'Harris', '1983-3-2', 2), ('Paul', 'Walker', '1991-5-1', 9), ('Carol', 'Young', '1992-12-17', 9), ('James', 'Baker', '1956-11-15', 4), ('Patricia', 'Adams', '1953-10-20', 6), ('Lisa', 'Green', '1967-5-6', 3), ('John', 'Johnson', '1946-3-10', 6); We have 31 users in the database. This should be enough to test basic queries. (By the way, note that we can specify multiple VALUES at a time in the INSERT statement, so multiple rows are inserted by a single query). Querying In phpMyAdmin, you can query data (search/select) by using the Search option in the top bar. You can try it, just enter some value into a value column.

If you specify more than one, multiple values will be used in the search. Don't worry about the operators for now, we're going to explain them later. PhpMyAdmin was initially a kind of helper, but now it's no longer interesting for us. We're going to use it just to run our queries and display the results. After the search, phpMyAdmin shows us a SELECT query. It always generates something more than is really needed. The basic query for selecting all Johns from our table would look like this: SELECT * FROM `user` WHERE `first_name` = 'John'; The command is probably understandable; the asterisk indicates that we want to select all the columns. As the result of the query, phpMyAdmin shows us something like this: Output 8 John Smith 1984-11-03 17 37 John Johnson 1946-3-10 6 Tables usually have a lot of columns, and we're usually interested only in some of them. In order not to overload the database by transferring loads of unnecessary data back to our application, we'll always try to specify just the columns we need. Let's suppose we only need the last names of the people