Generah Ben Generah Ben - 3 months ago 9
PHP Question

mysqli_query in php keep returning false

I have searched and i have tried different suggestion but it's not still working out for me. I don't really know where fault is coming from, I don't know what i am doing wrong. My query keep returning false and this is my code. Kindly help

$con = mysqli_connect($server, $username, $password);
if(!$con){
echo "Server Connection Failed". mysqli_error();
}
if(!mysqli_select_db($con, 'jerrytech')){
echo "Db connection failed";
exit();
}
$query = "
INSERT INTO enrol-form (name, phone, email, package, time)
VALUES ('$name', '$phone', '$email', '$package', now())
";

$result = mysqli_query($con, $query);
var_dump($result);
exit();

if(!$result){
echo "Error Communicating with Database";
//header ("Location: $url");
exit();
}
else {
echo 'Form Submitted!';
}


I am new to php programming. So please keep the explanation as easy as an intermediate person can cope with.

Answer

Try quoting your table name:

From:

INSERT INTO enrol-form 

To:

INSERT INTO `enrol-form`  

Edit for clarity: using a dash in the table name requires you to backtick it. A simpler name for the table might be enrolForm, which would not require the backticks.

Comments