David David - 29 days ago 7
PHP Question

Issue with the mysqli_query

mysqli_query
function not working

$query=mysqli_query($config,"INSERT into users (username,first_name,last_name,email,password) VALUES('$un','$fn','$ln','$em','$pass','$date','0')");");


When I echo the SQL query it worked fine but when I tried to insert into database its not doing anything and goes to next line .

I used a submit button like this
$signup = @$_POST['signup'];


signup
is the name of the submit button.

Answer

Informations

There are two basic syntaxes of INSERT INTO statement as follows:

INSERT INTO TABLE_NAME (column1, column2, column3,...columnN) VALUES (value1, value2, value3,...valueN);

You may not need to specify the column(s) name in the SQL query if you are adding values for all the columns of the table.

INSERT INTO TABLE_NAME VALUES (value1,value2,value3);

How to check errors

You can also check your connection if is estabilished or are there any errors with following code:

if (!$config) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

Or at the end you can check your query errors with :

echo mysqli_error($config);

More informations about debugging you can read here

Problems in your code

1. In your code you have too many ) it should be like follows:

$query=mysqli_query($config,"INSERT into users (username,first_name,last_name,email,password) VALUES('$un','$fn','$ln','$em','$pass','$date','0');");

2. Also you are trying to insert 7 values to 5 tables, there is too much in VALUES, or you have wrote too less tables.

3. Delete @ before your $_POST because maybe there is some error, and it cause that it will not show up. More informations can be found here

Comments