Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. <?php
  2. require('db.php');
  3. // If form submitted, insert values into the database.
  4. if (isset($_REQUEST['username'])){
  5. $username = stripslashes($_REQUEST['username']); // removes backslashes
  6. $username = mysqli_real_escape_string($con,$username); //escapes special characters in a string
  7. $email = stripslashes($_REQUEST['email']);
  8. $email = mysqli_real_escape_string($con,$email);
  9. $password = stripslashes($_REQUEST['password']);
  10. $password = mysqli_real_escape_string($con,$password);
  11.  
  12. $picture = $_FILES['foto']['tmp_name'];
  13. $img_name = $_FILES['foto']['name'];
  14. $dir = "/var/www/uploads/";
  15. $path = $dir.$img_name;
  16. move_uploaded_file( $picture, $path );
  17.  
  18. $date = date("Y-m-d H:i:s");
  19.  
  20. $query = "INSERT into `users` (username, password, email, picture, date) VALUES ('$username', '".md5($password)."', '$email', '$picture' ,'$date')";
  21. $result = mysqli_query($con,$query);
  22. if($result){
  23. echo "<div class='form'><h3>You are registered successfully.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
  24. }
  25. }else{
  26.  
  27. <form name="registration" action="" method="post">
  28. Upload Imagen : <input type="file" name="foto" />
  29. <input type="text" name="username" placeholder="Username" required />
  30. <input type="email" name="email" placeholder="Email" required />
  31. <input type="password" name="password" placeholder="Password" required />
  32. <input type="submit" name="submit" value="Register" />
  33. </form>
  34.  
  35.  
  36. minha Database
  37. CREATE TABLE `users` (
  38. `id` int(11) NOT NULL,
  39. `username` varchar(50) NOT NULL,
  40. `email` varchar(50) NOT NULL,
  41. `password` varchar(50) NOT NULL,
  42. `picture` varchar(100) NOT NULL,
  43. `level` tinyint(1) NOT NULL DEFAULT '0',
  44. `ative` tinyint(1) NOT NULL DEFAULT '0',
  45. `date` datetime NOT NULL
  46. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement