Connection problems

Asked

Viewed 36 times

-4

When sending the form to register the email entered in the field it should simply register in the database, but it does not register, how can I solve?

<?php    
    $conect = mysqli_connect('127.0.0.1','root@localhost','') or die ("erro de conecção");
    $banco = mysqli_select_db($conect,'oserpoeta');
    var_dump($banco)
?>

Page picks data

<?php     
    include = 'cad_&else.php';

    //Cadastra os dados
    $email = $_POST ["email"];    
    $link = "INSERT INTO 'newllester' ('email') VALUES ('$email')";    
    $qur = mysqli_query($link,'$sql')or die('erro:'.mysqli_error ());    
    header("location: http://serpoeta.localhost/serpoeta/")    
?>
    1. Read the function documentation mysqli_connect; 2. What is the return of var_dump($banco)? 3. Do not place single quotes in table name or column name - if you want to avoid conflict, use crases; 4. Read function documentation mysqli_query and review the order of the parameters; 5. What should be the variable $sql which it used in mysqli_query?
  • There will be no single quotes in the table name. Do not place single quotes in variables like => '$sql')or die(...);

  • Improving a line: $conect = mysqli_connect('127.0.0.1','root@localhost','','oserpoeta') or die ("erro de conecção"); You can already set the bank together.

1 answer

0


With mysqli you don’t need to use mysqli_select_db, just use the following code

$conect = mysqli_connect('servidor','nome_utilizador','palavra_pass', 'nome_da_db') or die ("erro de conecção");


$link = "INSERT INTO 'newllester' ('email') VALUES ('$email')";

$qur = mysqli_query($link,'$sql')or die('erro:'.mysqli_error ());

Also, the above code is poorly formulated. Where you say the query, the first data should be the connection to the database, ie

$qur = mysqli_query($conect, $link)or die('erro:'.mysqli_error ());

Browser other questions tagged

You are not signed in. Login or sign up in order to post.