Generah Ben Generah Ben -4 years ago 97
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);
echo "Server Connection Failed". mysqli_error();
if(!mysqli_select_db($con, 'jerrytech')){
echo "Db connection failed";
$query = "
INSERT INTO enrol-form (name, phone, email, package, time)
VALUES ('$name', '$phone', '$email', '$package', now())

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

echo "Error Communicating with Database";
//header ("Location: $url");
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 Source

Try quoting your table name:


INSERT INTO enrol-form 


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download