CyberShot Posted December 13, 2010 Share Posted December 13, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/221538-getting-empty-query-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 13, 2010 Share Posted December 13, 2010 $insert isn't your query string. It is the result of a $mysql->query("....") statement. What did you actually intend your code to do? Quote Link to comment https://forums.phpfreaks.com/topic/221538-getting-empty-query-error/#findComment-1146783 Share on other sites More sharing options...
CyberShot Posted December 13, 2010 Author Share Posted December 13, 2010 i intended it to insert the values from the form into the database. Why won't it work? Quote Link to comment https://forums.phpfreaks.com/topic/221538-getting-empty-query-error/#findComment-1146790 Share on other sites More sharing options...
CyberShot Posted December 13, 2010 Author Share Posted December 13, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/221538-getting-empty-query-error/#findComment-1146812 Share on other sites More sharing options...
PFMaBiSmAd Posted December 14, 2010 Share Posted December 14, 2010 $insert holds your query statement, which is a string, which is a TRUE value, so if($insert){ will always be TRUE. You need to test the value returned by $mysql->query($insert) in order to test if the query executed or failed. Quote Link to comment https://forums.phpfreaks.com/topic/221538-getting-empty-query-error/#findComment-1147129 Share on other sites More sharing options...
PFMaBiSmAd Posted December 14, 2010 Share Posted December 14, 2010 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] ... ] Quote Link to comment https://forums.phpfreaks.com/topic/221538-getting-empty-query-error/#findComment-1147133 Share on other sites More sharing options...
CyberShot Posted December 14, 2010 Author Share Posted December 14, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/221538-getting-empty-query-error/#findComment-1147224 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.