0

My PHP Code:

    <?php
//Connecting to sql db.
$mysqli = new mysqli("127.0.0.1", "admin", "pass", "enedpt_faculties");
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
mysqli_set_charset($mysqli,"utf8");


$user = $_POST['user'];
$pass = $_POST['pass'];
$nome = $_POST['nome'];
$apelido = $_POST['apelido'];
$fac = $_POST['fac'];
$data = $_POST['data'];
$email = $_POST['email'];

mysqli_query($mysqli,"`enedpt_faculties`.`users` (`user`, `pass`, `name`, `sname`, `facid`, `nasc`, `mail`)
VALUES ('$user', '$pass', '$nome', '$apelido, '$fac', '$data', '$email')");
?>

For some reason the query is not inserting, and there are no errors on the error Log. Please Help.

willier
  • 79
  • 8

1 Answers1

-1

You have to uae correct SQL.

An insert statement looks like this:

'INSERT INTO "table" (columnnames) VALUES (values)';

In your specific case you also have to concatenate the variables to the SQL-string:

'INSERT INTO `users` (`user`, `pass`, `name`, `sname`, `facid`, `nasc`, `mail`) VALUES ('.$user.', '.$pass.', '.$nome.', '.$apelido.', '.$fac.', '.$data.', '.$email.')'

You also can use back tics on the variables. Also you had some mistakes like missing quotes.

Igor Unger
  • 182
  • 2
  • 7
  • this is incorrect for many reasons. All that was missing in OP's code was `INSERT INTO`. Edit: which OP says it is part of their real code in comments. – Funk Forty Niner Dec 24 '16 at 17:17