web learning

HTML

CSS

PHP

JAVA SCRIPT

AJAX

EBOOKS

PROJECT

FORUM

<?php
    $con = mysql_connect("localhost","root","");
    if (!$con){
        die('Could not connect: ' . mysql_error());
      }
     
    // Select database
    mysql_select_db("Library", $con);
   
   
    // Insert users to the Users table   
    $sql = "INSERT INTO Users(Name, Password, UserType) VALUES ('Nisha', 'Nisha', 'Student')";   
    $result = mysql_query ($sql);
   
    // if successfully insert data into database, displays message "Successful".
    if($result){
        echo "Insert Command: $sql is successfully executed";
    }
    else {
        echo "ERROR while inserting the data";
    }

    /* read data from the database*/
    $query="SELECT * FROM Users";
    $result=mysql_query($query);
    $num=mysql_numrows($result);

    mysql_close();

    echo "<b><center>Database Output</center></b><br><br>";

    while($row = mysql_fetch_array($result)){
        echo $row['Name'] . " " . $row['UserType']. " " . $row['UserId'];
        echo "<br />";
    }

   
    mysql_close($con);
?>

Categories:

Leave a Reply