Guest User

Untitled

a guest
Jan 31st, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. $servername = "localhost";
  2. $username = "root";
  3. $password = "";
  4. $dbname = "banco";
  5.  
  6. # cria conexão
  7. $link = new mysqli($servername, $username, $password, $dbname);
  8.  
  9. # verifica conexão
  10. if ($link->connect_error) {
  11. die("Connection failed: " . $link->connect_error);
  12. }
  13.  
  14. # configura utf8 para caracteres especiais
  15. mysqli_set_charset( $conn, 'utf8');
  16.  
  17. $contrato = '';
  18. $nome = '';
  19. $tel = '';
  20.  
  21. $sql_select = "SELECT contrato, nome, tel FROM teste WHERE contrato LIKE '%$contrato%' AND nome LIKE '%$nome%' AND tel LIKE '%$tel%' ORDER BY contrato;";
  22.  
  23. $r = $link->query($sql_select);
  24.  
  25. # Primeiro var_dump
  26. # var_dump($r);
  27. # exit();
  28.  
  29. if(isset($_POST["inserir"])){
  30.  
  31. $sql_insert = "INSERT INTO teste (contrato, nome, tel) VALUES ("1000","João","DDD+número"); ";
  32.  
  33. $sql_insert .= "INSERT INTO teste (contrato, nome, tel) VALUES ("1001","Maria","DDD+número"); ";
  34.  
  35. $sql_insert .= "INSERT INTO teste (contrato, nome, tel) VALUES ("1002","José","DDD+número"); ";
  36.  
  37. $link->multi_query($sql_insert);
  38. # header("location: .");
  39. $r = $link->query($sql_select);
  40.  
  41. # Segundo var_dump
  42. # var_dump($r);
  43. # exit();
  44. }
  45. $link->close();
  46.  
  47. <form action="" method="post">
  48. <button type="submit" name="inserir" value="inserir">Inserir</button>
  49. </form>
  50.  
  51. object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(3) ["lengths"]=> NULL ["num_rows"]=> int(0) ["type"]=> int(0) }
  52.  
  53. bool(false)
  54.  
  55. object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(3) ["lengths"]=> NULL ["num_rows"]=> int(3) ["type"]=> int(0) }
Add Comment
Please, Sign In to add comment