Advertisement
Guest User

Untitled

a guest
Nov 15th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2. if($_SERVER['REQUEST_METHOD'] == 'POST'){
  3. //import database connetion
  4.  
  5. $serverName = "localhost";
  6. $userName = "root";
  7. $password = "";
  8. $dbName = "assignment";
  9. $con = new mysqli($serverName, $userName, $password, $dbName);
  10. if ($con->connect_error){
  11. die("Connection failed: ".$conn->connect_error);
  12. }
  13.  
  14. //grab value
  15. $m_name = $_POST["name"];
  16. $m_bday = $_POST["birthday"];
  17. $m_pass = $_POST["rpassword"];
  18. $upload = 1 ;
  19.  
  20. $image = $_FILES["image"]["tmp_name"];
  21. $img_temp = file_get_contents($image);
  22. $img = "uploads/";
  23. $img_file = $img. basename($_FILES["image"]["name"]);
  24. $img_type = pathinfo($img_file,PATHINFO_EXTENSION);
  25.  
  26. $check = getimagesize($_FILES["image"]["tmp_name"]);
  27.  
  28. if($check !== false) {
  29. echo "<h1>File is image - " . $image;
  30. $upload = 1;
  31. } else {
  32. echo "<center><h1>File is not an image.<br>";
  33. $upload = 0;
  34. }
  35.  
  36. if($upload == 1){
  37.  
  38. if($img_type != "jpg" && $img_type != "png" && $img_type != "jpeg" && $img_type != "gif" ) {
  39. echo "<h1>Sorry, the file type uploaded is not allowed.<br>";
  40. $upload = 0;
  41. }
  42.  
  43. else{
  44. echo "<h1>Image result: ". $image;
  45. $sql = "INSERT INTO member (name, birthday, password, image)
  46. VALUES ('$m_name', '$m_bday', '$m_pass', '$image')";
  47.  
  48.  
  49. if ( $con->query($sql)){
  50. header("Location: member.php");
  51. }
  52.  
  53.  
  54. }
  55. }
  56.  
  57. if ($upload == 0){
  58. echo "<h1>Error registration.<br>";
  59. echo "<h1><center><a href='register.php'>Back To Registration</a>";
  60. }
  61. /*if (isset($_FILES)){
  62. $image = $_FILES["image"]["tmp_name"];
  63. $img_temp = file_get_contents($image);
  64. echo "Image result: ". $image;
  65. }
  66. else{
  67. echo "error on image";
  68. }*/
  69.  
  70.  
  71. /*$sql = "INSERT INTO member (name, birthday, password, image)
  72. VALUES ('$m_name', '$m_bday', '$m_pass', '$image')";
  73.  
  74.  
  75. if ( $con->query($sql)){
  76. header("Location: login.php");
  77. }*/
  78.  
  79. $con->close();
  80. }
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement