Deleting data from a table

For deleting data from a table, you can again use the same mysql_query function. You need to pass MySQL delete query in this function. Example: <?php $query = “delete from employees where id = 3”; $result = mysql_query($query, $con); if(!$result) { die(“Error deleting data”,mysql_error()); } echo “Data deleted successfully”; ?> You can use all the other SQL … Read more

Update table data

  You can update table data by simply using update query in mysql_query function, just like other queries. Example: <?php require_once(“dbconnection.php”); $query = “update employees set name=”andy” where id = 2″; $result = mysql_query($query, $con); if(!$result) { die(“Error updatig data”,mysql_error()); } echo “Data updated successfully”; ?> As you see in above example using a function … Read more

Reading data from database table

  PHP is having multiple functions for reading data from database table. Those functions are mysql_fecth_array, mysql_fetch_assoc, mysql_fetch_object. We will see mysql_fetch_array in this chapter. While reading data from a table, these functions fetch data in the form of a single row at a time. Then we have to loop through to fetch all the … Read more

Inserting data in MySql table using PHP

mysql_query() For inserting data in MySql, PHP is having mysql_query() function where we can pass MySQL insert query to insert our data into database tables. Synatx: mysql_query(sql_query, connection); sql_query – its an sql query written in string format. connection –  its connection object returned from mysql_connect function. Before using this function lets create a new … Read more

Connecting database with PHP

We are having certain PHP functions for connecting database with PHP and using the database for various operations. Let’s see them in details. mysql_connect(): In PHP we are having mysql_connect() function to connect PHP application with MySql database. Syntax: connection mysql_connect(<server/host>,<username>,<password>); In above syntax: <server/host> – it’s a host or server of where your database is … Read more

Creating database and tables with phpMyAdmin

For creating database and tables, we can use phpmyadmin. We can use SQL commands with PHP to create a database table and insert, delete, update table records. We will see this in upcoming lessons. In this tutorial, I will show you how to create database and table directly using phpmyadmin. Creating database using below steps: You … Read more

MySql with PHP

The database is the most crucial part of every web application. We can use different types of databases with PHP but MySql is widely used. MySql is free and popular database system which can be used with PHP to create a web application with database handling. Let’s see in details MySql with PHP. Installation of … Read more

Session in PHP

What is Session? Session in PHP is used to store the information on the server which can be accessed at any page in your web application. Session store data on the server, unlike cookies which store data on client’s machine. Session data are stored in a file and that file resides on the server in … Read more

File upload using PHP forms

In File upload using PHP lets directly begin with the example. Consider below example and follow the steps to perform File upload using PHP. In the form add file input field. Set name, action and method attributes <form name=”file_upload” action=”uploads.php” method=”post” > <input type=”file” name=”photo” /> <input type=”submit” value=”Submit” /> </form> In above example, we have … Read more

Cookies in PHP

What are Cookies? Cookies in PHP are small text files which are saved by a browser in your computer. Cookies contain small pieces of data sent by the server, which can be accessed in any script. Cookies are just like PHP variables except that cookies contain that data even after you turn off the computer … Read more