nishimandhana

PHP

Jul 29th, 2017
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.88 KB | None | 0 0
  1. //CALL
  2. <?PHP
  3.  
  4. $username = $_POST['username'];
  5.  
  6. if ($username == "admin") {
  7.  
  8. print ("Welcome Administrator");
  9.  
  10. }
  11. else {
  12.  
  13. print ("You're not a member of this site");
  14.  
  15. }
  16.  
  17. ?>
  18. //CFORM
  19. <html>
  20. <head>
  21. <title>A BASIC HTML FORM</title>
  22. </head>
  23. <body>
  24.  
  25. <Form name ="form1" Method ="POST" Action ="call.php">
  26.  
  27. <INPUT TYPE = "TEXT" VALUE ="username" Name ="username">
  28. <INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Login">
  29.  
  30. </FORM>
  31.  
  32. </body>
  33. </html>
  34. //CONNECTION
  35. <?php
  36.  
  37.     $link = mysqli_connect("localhost","root" ,"");
  38.     if (!$link)
  39.     {
  40.     die('Could not connect: ' . mysqli_connect_error());
  41.     }
  42.     echo "Connect Successfully";
  43.  
  44. mysqli_close($link);
  45. ?>
  46. //CREATE TABLE
  47. <?php
  48.  
  49. $link = mysqli_connect("localhost", "root", "", "college");
  50.  
  51. // Check connection
  52. if($link === false){
  53.     die("ERROR: Could not connect. " . mysqli_connect_error());
  54. }
  55.  
  56. // Attempt create table query execution
  57. $sql = "CREATE TABLE empinfo(
  58.    fname VARCHAR(30) NOT NULL,
  59.    lname VARCHAR(30) NOT NULL,
  60.    email VARCHAR(70) NOT NULL UNIQUE
  61. )";
  62. if(mysqli_query($link, $sql)){
  63.     echo "Table created successfully.";
  64. } else{
  65.     echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
  66. }
  67.  
  68. // Close connection
  69. mysqli_close($link);
  70. ?>
  71. //DELETE
  72. <?php
  73. /* Attempt MySQL server connection. Assuming you are running MySQL
  74. server with default setting (user 'root' with no password) */
  75. $link = mysqli_connect("localhost", "root", "", "college");
  76.  
  77. // Check connection
  78. if($link === false){
  79.     die("ERROR: Could not connect. " . mysqli_connect_error());
  80. }
  81.  
  82. // Attempt delete query execution
  83. $sql = "DELETE FROM empinfo WHERE f_name='cse1'";
  84. if(mysqli_query($link, $sql)){
  85.     echo "Records were deleted successfully.";
  86. } else{
  87.     echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
  88. }
  89.  
  90. // Close connection
  91. mysqli_close($link);
  92. ?>
  93. //FINSERT
  94. <?php
  95.  
  96. $link = mysqli_connect("localhost", "root", "", "college");
  97.  
  98. // Check connection
  99. if($link === false){
  100.     die("ERROR: Could not connect. " . mysqli_connect_error());
  101. }
  102.  
  103. // Escape user inputs for security
  104. $first_name = $_POST['first'];
  105. $last_name = $_POST['last'];
  106. $email = $_POST['email'];
  107.  
  108. // attempt insert query execution
  109. $sql = "INSERT INTO empinfo (fname, lname, email) VALUES ('$fname', '$lname', '$email')";
  110. if(mysqli_query($link, $sql)){
  111.     echo "Records added successfully.";
  112. } else{
  113.     echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
  114. }
  115.  
  116. // close connection
  117. mysqli_close($link);
  118. ?>
  119. //UPDATE
  120. <?php
  121. /* Attempt MySQL server connection. Assuming you are running MySQL
  122. server with default setting (user 'root' with no password) */
  123. $link = mysqli_connect("localhost", "root", "", "college");
  124.  
  125. // Check connection
  126. if($link === false){
  127.     die("ERROR: Could not connect. " . mysqli_connect_error());
  128. }
  129.  
  130. // Attempt update query execution
  131. $sql = "UPDATE empinfo SET email='cse2_new@mail.com' WHERE fname= 'test' ";
  132. if(mysqli_query($link, $sql)){
  133.     echo "Records were updated successfully.";
  134. } else {
  135.     echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
  136. }
  137.  
  138. // Close connection
  139. mysqli_close($link);
  140. ?>
  141. //SELECT
  142. <?php
  143. $link = mysqli_connect("localhost", "root", "", "STUDENT");
  144.  
  145. // Check connection
  146. if($link === false){
  147.     die("ERROR: Could not connect. " . mysqli_connect_error());
  148. }
  149.  
  150. // Attempt select query execution
  151. $sql = "SELECT * FROM studentinfo";
  152. if($result = mysqli_query($link, $sql)){
  153.     if(mysqli_num_rows($result) > 0){
  154.         echo "<table>";
  155.             echo "<tr>";
  156.                 echo "<th>first_name</th>";
  157.                 echo "<th>last_name</th>";
  158.                 echo "<th>email</th>";
  159.             echo "</tr>";
  160.         while($row = mysqli_fetch_array($result)){
  161.             echo "<tr>";
  162.                 echo "<td>" . $row['fname'] . "</td>";
  163.                 echo "<td>" . $row['lname'] . "</td>";
  164.                 echo "<td>" . $row['email'] . "</td>";
  165.             echo "</tr>";
  166.         }
  167.         echo "</table>";
  168.         // Free result set
  169.         mysqli_free_result($result);
  170.     } else{
  171.         echo "No records matching your query were found.";
  172.     }
  173. } else{
  174.     echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
  175. }
  176.  
  177. // Close connection
  178. mysqli_close($link);
  179. ?>
  180. //PROCESS
  181. <?php
  182.  
  183. $username = $post['user'];
  184. $password = $post['psw'];
  185.  
  186.  
  187.  
  188. mysql_connect("localhost","root","");
  189. mysql_select_db("login");
  190.  
  191.  
  192.  
  193. $result = mysql_query("select * from users where username='$username' and psw='$password'")
  194. or die("falied to connect".mysql_error());
  195.  
  196. $row = mysql_fetch_array($result);
  197.  
  198. if($row['username'] == $username  && $row['psw'] == $password ){
  199.     print " welcome ";
  200. }else{
  201.     print " next time ";
  202. }
  203. ?>
  204.  
  205.  
  206. >
  207. //PHP1
  208. <html>
  209. <head>
  210. <title>Variables - Some Practice</title>
  211. </head>
  212. <body>
  213.  
  214. <?php print("Welcome to PHP Lab"); ?>
  215.  
  216. </body>
  217. </html>
Add Comment
Please, Sign In to add comment