Advertisement
stronk_8s

PHP_INTERNAL

Oct 13th, 2023 (edited)
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.56 KB | Source Code | 0 0
  1. //INSERT
  2.  
  3. <?php
  4. if(isset($_POST['submit']))//SUBMIT BUTTON NAME
  5. {
  6. $uname=$_POST['username'];
  7. $password=$_POST['password'];
  8. $sql="INSERT INTO `usertbl`(`id`, `username`, `password`) VALUES ('"."','".$uname."','".$password."')";//CHANGE ACCOURDING TO REQUIRED
  9. $result=mysqli_query($conn,$sql);
  10. if($result)
  11.     header('location:index.php');//replace index with required file
  12. }
  13. ?>
  14.  
  15.  
  16. //CAPTCHA
  17.  
  18. <?php
  19. session_start();
  20. $text=rand(10000,99999);
  21. $_SESSION["vercode"]=$text;
  22. $image_p=imagecreate(150,45);
  23. $black=imagecolorallocate($image_p,0,0,0);
  24. $white=imagecolorallocate($image_p,255,255,255);
  25. $font_size=10000;
  26. imagestring($image_p,$font_size,10,10,$text,$white);
  27. imagejpeg($image_p);
  28. ?>
  29.  
  30. <HTML>
  31. <img src="captcha.php"><br><br>
  32. Captcha: <input type="text" name="vercode" id="captcha"><br>
  33. </HTML>
  34.  
  35.  
  36.  
  37. //DISPLAY
  38.  
  39.  
  40.  
  41. <html>
  42.     <a href="viewuser.php">ADDUSER</a>//NAVIGATION FILE
  43. <?php
  44. include('connection.php');
  45. $sql="SELECT * FROM `usertbl`";
  46. $result=mysqli_query($conn,$sql);
  47. if($result->num_rows>0)
  48. {
  49.     echo "<table >
  50.    <th> Id </th>
  51.    <th> Name </th>
  52.    <th> Password </th>
  53.    <th> Edit </th>
  54.    <th> Delete </th>";
  55.     while($row=$result->fetch_assoc())//CREATE ASSOSIATIVE ARRAY OF TABLE DATA
  56.     {
  57.         echo '<tr>
  58.        <td>'.$row['id'].'</td>//FETCH ROW NAME
  59.        <td>'.$row['username'].'</td>
  60.        <td>'.$row['password'].'</td>
  61.        <td><a href="edit.php?edit_id='.$row['id'].'">Edit</a></td>
  62.        <td><a href="delete.php?delete_id='.$row['id'].'">Delete</a></td>
  63.        </tr>';
  64.     }
  65.     echo "</table>";
  66. }
  67. else
  68. {
  69.     echo "<table >
  70.    <th> Id </th>
  71.    <th> Name </th>
  72.    <th> Password </th>
  73.    <th> Edit </th>
  74.    <th> Delete </th>
  75.    </table>";
  76. }
  77. ?>
  78.  
  79.  
  80.  
  81.  
  82. //UPDATE
  83.  
  84.  
  85. <html>
  86.     <body>
  87. <?php
  88. include('connection.php');
  89. $id=$_GET['edit_id'];
  90. $sql="SELECT * FROM `usertbl` where id='".$id."'";
  91. $result=mysqli_query($conn,$sql);
  92. $data=$result->fetch_assoc();
  93. ?>
  94. <form action="" method="post">
  95. <label for="username">UserName:</label>
  96. <input type="text" id="username" name="username" placeholder="enter email" required value="<?php echo $data['username'];?>">
  97. <br><br>
  98. <label for="password">Password:</label>
  99. <input type="text" id="password" name="password" placeholder="enter password" required value="<?php echo $data['password']?>">
  100. <br><br>
  101. <input type="submit" id="submit" value="Submit" name="submit">
  102. </form>
  103. <?php
  104. if(isset($_POST['submit']))
  105. {
  106. $username= $_POST['username'];
  107. $password=$_POST['password'];
  108. $sql ="UPDATE usertbl SET username='".$username."',password='".$password."' where id='".$id."'";
  109. $result=mysqli_query($conn,$sql);
  110. if($result)
  111.     header('location:viewuser.php');
  112. }
  113. ?>
  114. </body>
  115. </html>
  116.  
  117.  
  118. //DELETE
  119.  
  120.  
  121. <html>
  122.     <body>
  123. <?php
  124. include('connection.php');
  125. $id=$_GET['delete_id'];
  126. $sql="DELETE FROM `usertbl` where id='".$id."'";
  127. $result=mysqli_query($conn,$sql);
  128. if($result)
  129.     header('location:viewuser.php');
  130. ?>
  131.     </body>
  132. </html>
  133.  
  134.  
  135.  
  136. //LOGIN
  137.  
  138.  
  139.  
  140. <!DOCTYPE html>
  141. <html lang="en">
  142. <head>
  143.     <meta charset="UTF-8">
  144.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  145.     <title>Login</title>
  146. </head>
  147. <body>
  148.     <?php
  149.     include 'connection.php';
  150.     if($_SERVER['REQUEST_METHOD']=="POST")
  151.     {
  152.     $username=$password="";
  153.     $username=$_POST['txtusername'];
  154.     $password=$_POST['txtpassword'];
  155.     $sql="select * from usertbl where username='".$username."' and password='".$password."'";
  156.     $result=mysqli_query($conn,$sql);
  157.     if (isset($_POST['submit'])) {
  158.  
  159.     if(!$result)
  160.     {
  161.         die('failed');
  162.     }
  163.     else
  164.     {
  165.         echo "<script>alert('sucess');</script>";
  166.         header('location:index.php');
  167.     }
  168.         session_start();
  169.         if($_POST["vercode"]!=$_SESSION["vercode"] OR $_SESSION["vercode"]=="")
  170.             echo "INVALID";
  171.         else
  172.             echo "valid";
  173. }
  174. }
  175.     ?>
  176.     <form method="post">
  177.         <input type="text" name="txtusername" id="username" placeholder="Enter Username" required>
  178.         <input type="password" name="txtpassword" id="password" placeholder="Enter Password" required>
  179.         <img src="captcha.php" alt="captcha"><br><br>
  180.         <input type="text" name="vercode" id="captcha" placeholder="Enter Captcha"><br>
  181.         <input type="submit" value="Submit" name="submit">
  182.     </form>
  183. </body>
  184. </html>
  185.  
  186.  
  187.  
  188. //  FILE UPLOAD
  189.  
  190.  
  191.  
  192. <?php
  193. session_start();
  194. ?>
  195. <!DOCTYPE html>
  196. <html>
  197. <head>
  198.     <meta charset="utf-8">
  199.     <title>
  200.     </title>
  201.  
  202.     <style type="text/css">
  203.         .error{
  204.             color: red;
  205.         }
  206.     </style>
  207. </head>
  208. <body>
  209. </body>
  210. <?php
  211.  
  212. $nameErr=$passErr=$jobErr=$emailErr=$salErr="";
  213. $name=$pass=$job=$email=$sal="";
  214. $set=1;
  215.  
  216. if(isset($_POST['submit']))
  217. {
  218.     if(empty($_POST['name']))
  219.     {
  220.         $set=0;
  221.         $nameErr="Name is required";
  222.     }
  223.     else
  224.     {
  225.         $set=1;
  226.         $name=$_POST['name'];
  227.         $_SESSION['name']=$name;
  228.         if(!preg_match("/^[a-zA-Z]*$/",$name))
  229.         {
  230.             $set=0;
  231.             $nameErr="Only letters are allowed";
  232.         }
  233.     }
  234.  
  235.  
  236.     if(empty($_POST['password']))
  237.     {
  238.         $set=0;
  239.         $passErr="Password is required";
  240.     }
  241.     else
  242.     {
  243.         $set=1;
  244.         $pass=$_POST['password'];
  245.         $_SESSION['pass']=$pass;
  246.     }
  247.  
  248.  
  249.     if(empty($_POST['jobtype']))
  250.     {
  251.         $set=0;
  252.         $jobErr="Jobtype is required";
  253.     }
  254.     else
  255.     {
  256.         $set=1;
  257.         $job=$_POST['jobtype'];
  258.         $_SESSION['job']=$job;
  259.     }
  260.  
  261.  
  262.     if(empty($_POST['email']))
  263.     {
  264.         $set=0;
  265.         $emailErr="Email is required";
  266.     }
  267.     else
  268.     {
  269.         $set=1;
  270.         $email=$_POST['email'];
  271.         $_SESSION['email']=$email;
  272.         if(!filter_var($email,FILTER_VALIDATE_EMAIL))
  273.         {
  274.             $set=0;
  275.            
  276.             $emailErr="Invalid email format";
  277.         }
  278.     }
  279.  
  280.  
  281.     if(empty($_POST['salary']))
  282.     {
  283.         $set=0;
  284.         $salErr="Salary is required";
  285.     }
  286.     else
  287.     {
  288.         $set=1;
  289.         $sal=$_POST['salary'];
  290.         $_SESSION['salary']=$sal;
  291.     }
  292.  
  293.     if(isset($_POST['remember']))
  294.     {
  295.         setcookie("name",$name);
  296.         setcookie('password',$pass);
  297.     }
  298.    
  299.  
  300.     if($set==1)
  301.     {
  302.         header('location:form_data.php');
  303.     }
  304.    
  305.  
  306. }
  307.  
  308. ?>
  309.     <form action="#" method="post" enctype="multipart/form-data">
  310.         <p><span class="error">* Required field</span></p>
  311.         Username:
  312.         <input type="text" name="name" value="<?php echo $name; ?>"><span class="error"> * <?php echo $nameErr; ?></span><br><br>
  313.         Password:
  314.         <input type="text" name="password" value="<?php echo $pass; ?>"><span class="error"> * <?php echo $passErr; ?></span><br><br>
  315.         JobType:
  316.         <input type="text" name="jobtype" value="<?php echo $job; ?>"><span class="error"> * <?php echo $jobErr; ?></span><br><br>
  317.         Email ID:
  318.         <input type="text" name="email" value="<?php echo $email; ?>"><span class="error"> * <?php echo $emailErr; ?></span><br><br>
  319.         Salary:
  320.         <input type="number" name="salary" value="<?php echo $sal; ?>"><span class="error"> * <?php echo $salErr; ?></span><br><br>
  321.         Profile:
  322.         <input type="file" name="uploads[]" multiple>
  323.         <input type="submit" name="fupload" value="Upload"><br><br>
  324.  
  325.         <input type="checkbox" name="remember">Remember Me<br><br>
  326.         <input type="submit" name="submit" value="Submit">
  327.        
  328.        
  329.     </form>
  330.  
  331.     <?php
  332.  
  333.     if(isset($_POST['fupload']))
  334.     {
  335.  
  336.         $target_dir="uploads/";
  337.  
  338.         if(!empty(array_filter($_FILES['uploads']['name'])))
  339.         {
  340.             foreach($_FILES['uploads']['tmp_name'] as $key=>$value)
  341.             {
  342.                 $tmp_file=$_FILES['uploads']['tmp_name'][$key];
  343.                 $target_file=$_FILES['uploads']['name'][$key];
  344.                 $path=$target_dir.$target_file;
  345.  
  346.                 if(move_uploaded_file($tmp_file,$path))
  347.                 {
  348.                     echo "$target_file successfully uploaded <br>";
  349.                 }
  350.                 else
  351.                 {
  352.                     echo "Error uploading $target_file <br>";
  353.                 }
  354.             }
  355.         }
  356.  
  357.         else
  358.         {
  359.             echo "No such file is selected";
  360.         }
  361.  
  362. }
  363.  
  364.     ?>
  365. </body>
  366. </html>
  367.  
Tags: php internal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement