Skip to main content

Posts

POPULATE DROPDOWN MENU FROM MYSQL

Populate  drop down menu from MYSQL: 1 2 3 4 5 6 7 8 <select name="user"> <?php $sql = mysqli_query ( $connect , "SELECT name FROM users" ); while ( $row = $sql -> fetch_assoc () ) { echo '<option value = "' . $row [ 'name' ] . '">' . $row [ 'name' ] . "</option>" ; } ?> </select> Show a drop down selected value coming from database: 1 2 3 4 5 6 7 8 9 10 11 <select name="user"> <?php $name = $users [ 'name' ]; $sql = mysqli_query ( $connect , "SELECT name FROM users" ); while ( $row = $sql -> fetch_assoc () ) { $selected = ( $row [ 'name' ] == $name ) ? 'selected="selected"' : '' ; echo '<option value="' . $row [ 'name' ] . '" ' . $selected . '>' . $row [ 'name...

SIMPLE PAGINATION USING PHP AND BOOTSTRAP

Hello guys, today we will learn how to create a simple pagination using PHP and Bootstrap. What is pagination? If you have a form which allows the user to browse through the rows in a database table, what do you do if that table has hundreds or even thousands of rows? It would not be a good idea to show all those rows in a single form, instead you should split the database output into more manageable chunks or 'pages'. There are two things you must do: Decide on the maximum number of database rows that can be included in each page. You may hard code this value, or (my preferred method) you can define it in a variable so that the value may be changed at runtime. You then need to inform the user that other 'pages' are available and provide a mechanism whereby the user is able to select a different 'page' of details. This is nothing but pagination area.                                 This area tells the ...

MYSQL CONNECTION USING PDO WITH PHP

Hello guys, In the previous tutorial we have seen how to connect to MySQL database with PHP using MySQLi. Today we will learn how to connect with PDO. As a PHP programmer we have learned how to access database by using either MySQL and MySQLi. As of PHP 5.1, there's a better way. PHP Data Objects(PDO) provide methods for prepared statements and working with objects that will make you far more productive! PDO Introduction :        PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. Database Support:       The extension can support any database that a PDO driver has been written for. The following drivers currently implement the PDO interface: PDO_CUBRID Cubrid PDO_DBLIB FreeTDS / Microsoft SQL Server / Sybase PDO_FIREBIRD Firebird PDO_I...

MYSQL DATABASE CONNECTION WITH PHP

Hello friends, today we will learn how to connect to  MySQL  database with PHP. This tutorial will require a MySQL database and a web development environment using mysql, apache and php and a simple text editor. The tutorial takes you through establishing a  MySQL  connection using php on a web page, connecting to a  MySQL  table and retrieving the results and displaying them back on the web page. Earlier versions of PHP used the  MySQL  extension.However, this extension was depreciated in 2012. Later can work with  MySQL  database using MySQLi extension (the "i" stands for improved) PDO (PHP Data Objects)        The main difference between these two are if you want to switch your project to another database PDO makes it easy(since it can connect 12 different databases). You only have to change the connection string and a few queries. With MySQLi, you will need to rewrite the entire code - queries included.In this t...

PHP FROM COMMAND LINE

Hello guys, today we will learn how to write PHP programs through command line. Generally, PHP is use for web applications but  there are occasions where we can use command line such as automatic mail sending, log tracking, cron jobs etc. PHP supports CLI SAPI(Command Line Interface Server API) for executing the script from command line. This SAPI will differ from other interfaces based on the IO practices, configuration defaults, buffering and more. For example, IO practices – it will not support PHP request method (GET, POST). Instead, it uses IO streams. Command line execution time –  In the command line, the execution time limit is unlimited by default. Buffering – implicit_flush is enabled to display output. It also supports output buffering. Some of the PHP CLI SAPI commands: Command Description -i To display command line PHP info. -v To show version details. -r To execute PHP script without delimiters -f To execute PHP file. -l To check the syntax of the...

SET, GET AND UNSET SESSION VARIABLES IN PHP

Session is a way to store information across multiple pages in a website. How to start a session: A session can be started  by using session_start() function.We can set session variable by using PHP global variable $_SESSION. consider an example: create a new page demo1.php and start a new PHP session in this page and set some session variables. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 <?php // Start the session session_start (); ?> <!DOCTYPE html> <html> <body> <?php // Set session variables $_SESSION [ "username" ] = "sowmya" ; $_SESSION [ "email" ] = "sowmya.vejerla@gmail.com" ; echo 'username : ' . $_SESSION [ 'username' ]; echo '<br>' ; echo 'email : ' . $_SESSION [ 'email' ]; ?> </body> </html> Next we create another page demo2.php ,from this page we will access  the session variables that we set ...

PHP AND HTML IN ONE PAGE

There are two ways you can use HTML in your PHP page. The first way is  by placing HTML outside the PHP tags.You can put it in the middle if you can open and close PHP tags. Here is an example for it: 1 2 3 4 5 6 7 8 <html> <title>PHP INSIDE HTML</title> <body> <h1>Example</h1> <?php echo "hello world" ?> </body> </html> As you can see you can use any HTML tags without need any extra work,except saving as .php file. The second way is by using PRINT and ECHO statements. Here is an example for it: 1 2 3 4 5 6 7 8 9 <?php Echo "<html>" ; Echo "<title>HTML with PHP</title>" ; Echo "<b>My Example</b>" ; //your php code here Print "<i>Print works too!</i>" ; ?> This is simplest and quick method if you only have a line or so to do.Using both these methods you can embed HTML and PHP in same page to gave them a nice forma...