Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CALL
- <?PHP
- $username = $_POST['username'];
- if ($username == "admin") {
- print ("Welcome Administrator");
- }
- else {
- print ("You're not a member of this site");
- }
- ?>
- //CFORM
- <html>
- <head>
- <title>A BASIC HTML FORM</title>
- </head>
- <body>
- <Form name ="form1" Method ="POST" Action ="call.php">
- <INPUT TYPE = "TEXT" VALUE ="username" Name ="username">
- <INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Login">
- </FORM>
- </body>
- </html>
- //CONNECTION
- <?php
- $link = mysqli_connect("localhost","root" ,"");
- if (!$link)
- {
- die('Could not connect: ' . mysqli_connect_error());
- }
- echo "Connect Successfully";
- mysqli_close($link);
- ?>
- //CREATE TABLE
- <?php
- $link = mysqli_connect("localhost", "root", "", "college");
- // Check connection
- if($link === false){
- die("ERROR: Could not connect. " . mysqli_connect_error());
- }
- // Attempt create table query execution
- $sql = "CREATE TABLE empinfo(
- fname VARCHAR(30) NOT NULL,
- lname VARCHAR(30) NOT NULL,
- email VARCHAR(70) NOT NULL UNIQUE
- )";
- if(mysqli_query($link, $sql)){
- echo "Table created successfully.";
- } else{
- echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
- }
- // Close connection
- mysqli_close($link);
- ?>
- //DELETE
- <?php
- /* Attempt MySQL server connection. Assuming you are running MySQL
- server with default setting (user 'root' with no password) */
- $link = mysqli_connect("localhost", "root", "", "college");
- // Check connection
- if($link === false){
- die("ERROR: Could not connect. " . mysqli_connect_error());
- }
- // Attempt delete query execution
- $sql = "DELETE FROM empinfo WHERE f_name='cse1'";
- if(mysqli_query($link, $sql)){
- echo "Records were deleted successfully.";
- } else{
- echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
- }
- // Close connection
- mysqli_close($link);
- ?>
- //FINSERT
- <?php
- $link = mysqli_connect("localhost", "root", "", "college");
- // Check connection
- if($link === false){
- die("ERROR: Could not connect. " . mysqli_connect_error());
- }
- // Escape user inputs for security
- $first_name = $_POST['first'];
- $last_name = $_POST['last'];
- $email = $_POST['email'];
- // attempt insert query execution
- $sql = "INSERT INTO empinfo (fname, lname, email) VALUES ('$fname', '$lname', '$email')";
- if(mysqli_query($link, $sql)){
- echo "Records added successfully.";
- } else{
- echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
- }
- // close connection
- mysqli_close($link);
- ?>
- //UPDATE
- <?php
- /* Attempt MySQL server connection. Assuming you are running MySQL
- server with default setting (user 'root' with no password) */
- $link = mysqli_connect("localhost", "root", "", "college");
- // Check connection
- if($link === false){
- die("ERROR: Could not connect. " . mysqli_connect_error());
- }
- // Attempt update query execution
- $sql = "UPDATE empinfo SET email='cse2_new@mail.com' WHERE fname= 'test' ";
- if(mysqli_query($link, $sql)){
- echo "Records were updated successfully.";
- } else {
- echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
- }
- // Close connection
- mysqli_close($link);
- ?>
- //SELECT
- <?php
- $link = mysqli_connect("localhost", "root", "", "STUDENT");
- // Check connection
- if($link === false){
- die("ERROR: Could not connect. " . mysqli_connect_error());
- }
- // Attempt select query execution
- $sql = "SELECT * FROM studentinfo";
- if($result = mysqli_query($link, $sql)){
- if(mysqli_num_rows($result) > 0){
- echo "<table>";
- echo "<tr>";
- echo "<th>first_name</th>";
- echo "<th>last_name</th>";
- echo "<th>email</th>";
- echo "</tr>";
- while($row = mysqli_fetch_array($result)){
- echo "<tr>";
- echo "<td>" . $row['fname'] . "</td>";
- echo "<td>" . $row['lname'] . "</td>";
- echo "<td>" . $row['email'] . "</td>";
- echo "</tr>";
- }
- echo "</table>";
- // Free result set
- mysqli_free_result($result);
- } else{
- echo "No records matching your query were found.";
- }
- } else{
- echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
- }
- // Close connection
- mysqli_close($link);
- ?>
- //PROCESS
- <?php
- $username = $post['user'];
- $password = $post['psw'];
- mysql_connect("localhost","root","");
- mysql_select_db("login");
- $result = mysql_query("select * from users where username='$username' and psw='$password'")
- or die("falied to connect".mysql_error());
- $row = mysql_fetch_array($result);
- if($row['username'] == $username && $row['psw'] == $password ){
- print " welcome ";
- }else{
- print " next time ";
- }
- ?>
- >
- //PHP1
- <html>
- <head>
- <title>Variables - Some Practice</title>
- </head>
- <body>
- <?php print("Welcome to PHP Lab"); ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment