Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.

Similar presentations


Presentation on theme: "PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect."— Presentation transcript:

1 PHP SQL

2 Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect = mysql_connect("localhost","root","") or die("Cannot Connect"); localhost server name root username password die display error message when cannot connect

3 PHP SQL mysql_select_db("database_name") Selecting a database within a connected database server. Eg mysql_select_db(phpdb") or die("Database not found"); phpdb database name die display error message when data base not exisit

4 PHP SQL mysql_query('TYPE_HERE_YOUR_MYSQL_QUERY') This function is used to run specific queries on our database Eg $query= mysql_query("select * From login_table WHERE username='$username'"); Login_table table name

5 PHP SQL $numrows = mysql_num_rows($query); Count no of row that satisfies the query

6 PHP SQL Login page User name Password

7 PHP SQL 'login.php page <?php $username = $_POST['username']; $password = $_POST['password']; if($username && $password)//check username and password null { $connect = mysql_connect("localhost","root","") or die("Cannot Connect"); mysql_select_db(phpdb") or die("Database not found"); $query= mysql_query("select * From login_table WHERE username='$username'"); $numrows = mysql_num_rows($query); echo $numrows; } else die("Please enter username and Password!"); ?>

8 PHP SQL <?php $username = $_POST['username']; $password = $_POST['password']; if($username && $password) { $connect = mysql_connect("localhost","root","") or die("Couldn't connect!"); mysql_select_db("phpdb") or die("Couldn't find db"); $query= mysql_query("SELECT * From login_table WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) { while($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } if($username==$dbusername&&$password==$dbpassword) { //code for in echo "You're in!"; } else echo "Incorrect password!"; } else die("That user does't exist!"); } else die("Please enter username and Password!"); ?>

9 MySQL


Download ppt "PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect."

Similar presentations


Ads by Google