Advertisement
Guest User

Untitled

a guest
Nov 10th, 2018
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $db = "paptest";
  6.  
  7. // Create connection
  8. $conn = new mysqli($servername, $username, $password, $db);
  9.  
  10. // Check connection
  11. if ($conn->connect_error) {
  12. die("Connection failed: " . $conn->connect_error);
  13. }
  14. // echo "Connected successfully";
  15.  
  16. $nomeint = $_POST['nome'];
  17. $nome = explode(' ',trim($nomeint));
  18. $pieces = explode(' ', $nomeint);
  19. $sobnome = array_pop($pieces);
  20. $user = $nome[0] . $sobnome;
  21. echo $user;
  22.  
  23. $mysqli = new mysqli($servername, $username, $password, $db);
  24. $result = $mysqli->query("SELECT User FROM alunos WHERE User = $user");
  25. if($result->num_rows == 0) {
  26. $sql = "INSERT INTO alunos (User) VALUES ($user)";
  27. } else {
  28. // $mysqli = new mysqli($servername, $username, $password, $db);
  29. // $L_user = mysql_query("SELECT MAX('ID') FROM alunos");
  30. // echo $L_user;
  31.  
  32. }
  33. $mysqli->close();
  34. ?>
  35. <!DOCTYPE html>
  36. <html>
  37. <head>
  38. <title></title>
  39. </head>
  40. <body>
  41. <form method="POST">
  42. <input type="text" placeholder="Nome" name="nome">
  43. <input type="Submit" value="Submit" id="Randomizer">
  44. </form>
  45. <h1></h1>
  46. </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement