Hi
I have a problem with inserting into the database.
This is my code :

    $insert = $db_con->query("INSERT INTO users (username,password,email,com-name,com-logo,com-phone,com-mobile) 
        VALUES('".$username."','".$enc_pass."','".$email."','".$com_name."','".$profile_path."','".$com_phone."','".$com_mobile."')");

Recommended Answers

All 14 Replies

What's the error?

You probably need to enclose the column names with hyphens in backticks.

there is no error !! That's my problem!

Add error checking.

Did you try my suggestion?

I'm new in mysqli, I'v tried this is it correct ?

    $insert = $db_con->query("INSERT INTO users (username,password,email,com-name,com-logo,com-phone,com-mobile) 
        VALUES('".$username."','".$enc_pass."','".$email."','".$com_name."','".$profile_path."','".$com_phone."','".$com_mobile."')")
        or die($db_con->error()); 

is it correct ?
I didn't understand your suggestion to be honest!

I got the error :
Erreur de syntaxe pr�s de '-name,com-logo,com-phone,com-mobile) VALUES('1','c4ca4238a0b923820dcc509a6f7' � la ligne 1
Idon't know why it's not in English!

You still didn't do as I suggested.

I didn't understand what is you suggestion ! :(
can you rephrase your suggestion so I can understand it please? :)

Is the username '1'?

yes I'm testing if it's work or not and didn't work.I'v tried several times with different values like : john,mark...etc but didn't work

Since your column names contain hyphens, they need to be enclosed in backticks:

`column-name`

^
didn't work :(

The error :
Erreur de syntaxe près de ''users' ('username' ,'password' ,'email' ,'com-name' ,'com-logo' ,'com-phone' ,'' à la ligne 1

the code:

    $insert = $db_con->query("INSERT INTO 'users' ('username' ,'password' ,'email' ,'com-name' ,'com-logo' ,'com-phone' ,'com-mobile') 
        VALUES('".$username."','".$enc_pass."','".$email."','".$com_name."','".$profile_path."','".$com_phone."','".$com_mobile."')")
        or die($db_con->error); 

You added single quotes, not backticks...

^
Thanks it did work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.