Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //INSERT
- <?php
- if(isset($_POST['submit']))//SUBMIT BUTTON NAME
- {
- $uname=$_POST['username'];
- $password=$_POST['password'];
- $sql="INSERT INTO `usertbl`(`id`, `username`, `password`) VALUES ('"."','".$uname."','".$password."')";//CHANGE ACCOURDING TO REQUIRED
- $result=mysqli_query($conn,$sql);
- if($result)
- header('location:index.php');//replace index with required file
- }
- ?>
- //CAPTCHA
- <?php
- session_start();
- $text=rand(10000,99999);
- $_SESSION["vercode"]=$text;
- $image_p=imagecreate(150,45);
- $black=imagecolorallocate($image_p,0,0,0);
- $white=imagecolorallocate($image_p,255,255,255);
- $font_size=10000;
- imagestring($image_p,$font_size,10,10,$text,$white);
- imagejpeg($image_p);
- ?>
- <HTML>
- <img src="captcha.php"><br><br>
- Captcha: <input type="text" name="vercode" id="captcha"><br>
- </HTML>
- //DISPLAY
- <html>
- <a href="viewuser.php">ADDUSER</a>//NAVIGATION FILE
- <?php
- include('connection.php');
- $sql="SELECT * FROM `usertbl`";
- $result=mysqli_query($conn,$sql);
- if($result->num_rows>0)
- {
- echo "<table >
- <th> Id </th>
- <th> Name </th>
- <th> Password </th>
- <th> Edit </th>
- <th> Delete </th>";
- while($row=$result->fetch_assoc())//CREATE ASSOSIATIVE ARRAY OF TABLE DATA
- {
- echo '<tr>
- <td>'.$row['id'].'</td>//FETCH ROW NAME
- <td>'.$row['username'].'</td>
- <td>'.$row['password'].'</td>
- <td><a href="edit.php?edit_id='.$row['id'].'">Edit</a></td>
- <td><a href="delete.php?delete_id='.$row['id'].'">Delete</a></td>
- </tr>';
- }
- echo "</table>";
- }
- else
- {
- echo "<table >
- <th> Id </th>
- <th> Name </th>
- <th> Password </th>
- <th> Edit </th>
- <th> Delete </th>
- </table>";
- }
- ?>
- //UPDATE
- <html>
- <body>
- <?php
- include('connection.php');
- $id=$_GET['edit_id'];
- $sql="SELECT * FROM `usertbl` where id='".$id."'";
- $result=mysqli_query($conn,$sql);
- $data=$result->fetch_assoc();
- ?>
- <form action="" method="post">
- <label for="username">UserName:</label>
- <input type="text" id="username" name="username" placeholder="enter email" required value="<?php echo $data['username'];?>">
- <br><br>
- <label for="password">Password:</label>
- <input type="text" id="password" name="password" placeholder="enter password" required value="<?php echo $data['password']?>">
- <br><br>
- <input type="submit" id="submit" value="Submit" name="submit">
- </form>
- <?php
- if(isset($_POST['submit']))
- {
- $username= $_POST['username'];
- $password=$_POST['password'];
- $sql ="UPDATE usertbl SET username='".$username."',password='".$password."' where id='".$id."'";
- $result=mysqli_query($conn,$sql);
- if($result)
- header('location:viewuser.php');
- }
- ?>
- </body>
- </html>
- //DELETE
- <html>
- <body>
- <?php
- include('connection.php');
- $id=$_GET['delete_id'];
- $sql="DELETE FROM `usertbl` where id='".$id."'";
- $result=mysqli_query($conn,$sql);
- if($result)
- header('location:viewuser.php');
- ?>
- </body>
- </html>
- //LOGIN
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Login</title>
- </head>
- <body>
- <?php
- include 'connection.php';
- if($_SERVER['REQUEST_METHOD']=="POST")
- {
- $username=$password="";
- $username=$_POST['txtusername'];
- $password=$_POST['txtpassword'];
- $sql="select * from usertbl where username='".$username."' and password='".$password."'";
- $result=mysqli_query($conn,$sql);
- if (isset($_POST['submit'])) {
- if(!$result)
- {
- die('failed');
- }
- else
- {
- echo "<script>alert('sucess');</script>";
- header('location:index.php');
- }
- session_start();
- if($_POST["vercode"]!=$_SESSION["vercode"] OR $_SESSION["vercode"]=="")
- echo "INVALID";
- else
- echo "valid";
- }
- }
- ?>
- <form method="post">
- <input type="text" name="txtusername" id="username" placeholder="Enter Username" required>
- <input type="password" name="txtpassword" id="password" placeholder="Enter Password" required>
- <img src="captcha.php" alt="captcha"><br><br>
- <input type="text" name="vercode" id="captcha" placeholder="Enter Captcha"><br>
- <input type="submit" value="Submit" name="submit">
- </form>
- </body>
- </html>
- // FILE UPLOAD
- <?php
- session_start();
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>
- </title>
- <style type="text/css">
- .error{
- color: red;
- }
- </style>
- </head>
- <body>
- </body>
- <?php
- $nameErr=$passErr=$jobErr=$emailErr=$salErr="";
- $name=$pass=$job=$email=$sal="";
- $set=1;
- if(isset($_POST['submit']))
- {
- if(empty($_POST['name']))
- {
- $set=0;
- $nameErr="Name is required";
- }
- else
- {
- $set=1;
- $name=$_POST['name'];
- $_SESSION['name']=$name;
- if(!preg_match("/^[a-zA-Z]*$/",$name))
- {
- $set=0;
- $nameErr="Only letters are allowed";
- }
- }
- if(empty($_POST['password']))
- {
- $set=0;
- $passErr="Password is required";
- }
- else
- {
- $set=1;
- $pass=$_POST['password'];
- $_SESSION['pass']=$pass;
- }
- if(empty($_POST['jobtype']))
- {
- $set=0;
- $jobErr="Jobtype is required";
- }
- else
- {
- $set=1;
- $job=$_POST['jobtype'];
- $_SESSION['job']=$job;
- }
- if(empty($_POST['email']))
- {
- $set=0;
- $emailErr="Email is required";
- }
- else
- {
- $set=1;
- $email=$_POST['email'];
- $_SESSION['email']=$email;
- if(!filter_var($email,FILTER_VALIDATE_EMAIL))
- {
- $set=0;
- $emailErr="Invalid email format";
- }
- }
- if(empty($_POST['salary']))
- {
- $set=0;
- $salErr="Salary is required";
- }
- else
- {
- $set=1;
- $sal=$_POST['salary'];
- $_SESSION['salary']=$sal;
- }
- if(isset($_POST['remember']))
- {
- setcookie("name",$name);
- setcookie('password',$pass);
- }
- if($set==1)
- {
- header('location:form_data.php');
- }
- }
- ?>
- <form action="#" method="post" enctype="multipart/form-data">
- <p><span class="error">* Required field</span></p>
- Username:
- <input type="text" name="name" value="<?php echo $name; ?>"><span class="error"> * <?php echo $nameErr; ?></span><br><br>
- Password:
- <input type="text" name="password" value="<?php echo $pass; ?>"><span class="error"> * <?php echo $passErr; ?></span><br><br>
- JobType:
- <input type="text" name="jobtype" value="<?php echo $job; ?>"><span class="error"> * <?php echo $jobErr; ?></span><br><br>
- Email ID:
- <input type="text" name="email" value="<?php echo $email; ?>"><span class="error"> * <?php echo $emailErr; ?></span><br><br>
- Salary:
- <input type="number" name="salary" value="<?php echo $sal; ?>"><span class="error"> * <?php echo $salErr; ?></span><br><br>
- Profile:
- <input type="file" name="uploads[]" multiple>
- <input type="submit" name="fupload" value="Upload"><br><br>
- <input type="checkbox" name="remember">Remember Me<br><br>
- <input type="submit" name="submit" value="Submit">
- </form>
- <?php
- if(isset($_POST['fupload']))
- {
- $target_dir="uploads/";
- if(!empty(array_filter($_FILES['uploads']['name'])))
- {
- foreach($_FILES['uploads']['tmp_name'] as $key=>$value)
- {
- $tmp_file=$_FILES['uploads']['tmp_name'][$key];
- $target_file=$_FILES['uploads']['name'][$key];
- $path=$target_dir.$target_file;
- if(move_uploaded_file($tmp_file,$path))
- {
- echo "$target_file successfully uploaded <br>";
- }
- else
- {
- echo "Error uploading $target_file <br>";
- }
- }
- }
- else
- {
- echo "No such file is selected";
- }
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement