Jump to content

getting empty query error


CyberShot

Recommended Posts

I am getting an empty query error on this line

 

$mysql->query($insert);

 

 

here is my code

if(isset($_POST['submit'])){
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$companyName = $_POST['companyName'];
$homePhone = $_POST['homePhone'];
$cellPhone = $_POST['cellPhone'];
$companyPhone = $_POST['companyPhone'];

//checking the values are filled
//echo $firstName. " " . $lastName . " " . $companyName . " " . $homePhone . " " . $cellPhone . " " . $companyPhone;

$insert = $mysql->query("INSERT INTO names('firstName','lastName','companyName'), phone('home','cell','company') values('$firstName','$lastName','$companyName','$homePhone','$cellPhone','$companyPhone'");

$mysql->query($insert);

if($insert){
echo "success";
}
else
{
mysql_error();
}

}

 

I got a connection to the database, I tested for it. I can't find the problem.

this is the error I get

 

Warning: mysqli::query() [mysqli.query]: Empty query in C:\wamp\www\test\formData.php on line 23

 

which is this line

$mysql->query($insert);

 

Link to comment
Share on other sites

okay, I figured out what I did wrong and I got the success message, but the table doesn't show the information. I changed it to this

$insert = ("INSERT INTO names('firstName','lastName','companyName'), phone('home','cell','company') values('$firstName','$lastName','$companyName','$homePhone','$cellPhone','$companyPhone'");

$mysql->query($insert);

Link to comment
Share on other sites

Once you actually test the result of your query and use the correct $mysql->error code to find why it is failing, you will find that your query makes no sense. You are apparently trying to make a mulit-table INSERT query and there is no such thing. The following is the syntax definition for an insert query -

 

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [iGNORE]

    [iNTO] tbl_name [(col_name,...)]

    {VALUES | VALUE} ({expr | DEFAULT},...),(...),...

    [ ON DUPLICATE KEY UPDATE

      col_name=expr

        [, col_name=expr] ... ]

 

 

Link to comment
Share on other sites

if there is so such thing as a multiple table insert query, why am I finding them online when I google it? I have re worked my query several times and it is getting better. I also fixed the error code. it doesn't give me the error anymore. It also doesn't give me an error on the insert query. right now, it just doesn't insert. The code says it does but the table is empty

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.