1 / 9

PHP SQL

PHP SQL. PHP SQL. 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"); l ocalhost  server name r oot username

benita
Download Presentation

PHP SQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP SQL

  2. PHP SQL • 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 • <html> • <form action='login.php' method='POST'> • User name <input type='text' name='username'><br> • Password <input type='password' name='password'><br> • <input type='submit' name='Log in'> • </form> • </html>

  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

More Related