Z33M@N Posted March 25, 2009 Share Posted March 25, 2009 Hi guys I'm new here I'm getting the following error Error: Query was empty. Below is my code <? include('config.php'); // values sent from form $title=$_POST['title']; $description=$_POST['description']; $price=$_POST['price']; $town=$_POST['town']; $area=$_POST['area']; $category=$_POST['category']; $subcat=$_POST['subcat']; // Insert data into database $sql="INSERT INTO ads2(title, description, price, area, town, adDate, category, subcat)VALUES('$title', '$description', '$price', '$town','NOW()', '$area', '$category', '$subcat')"; echo $sql; $result=mysql_query($sql); // if suceesfully inserted data into database, send confirmation link to email if (!mysql_query($query)) { die('Error: ' . mysql_error()); } echo "Thanks your ad was added!"; ?> I've tried everything I know so no luck so far. I did echo the query but the datetime doesn't show. I even manually inserted but still empty. Help will be appreciated Link to comment https://forums.phpfreaks.com/topic/151124-inserting-date-into-mysql-error-empty-string/ Share on other sites More sharing options...
lonewolf217 Posted March 25, 2009 Share Posted March 25, 2009 looks like you never closed your parenthesis for VALUES( Link to comment https://forums.phpfreaks.com/topic/151124-inserting-date-into-mysql-error-empty-string/#findComment-793891 Share on other sites More sharing options...
Z33M@N Posted March 25, 2009 Author Share Posted March 25, 2009 looks like you never closed your parenthesis for VALUES( Thanks for that I fixed it but I still get the same error :-\ Link to comment https://forums.phpfreaks.com/topic/151124-inserting-date-into-mysql-error-empty-string/#findComment-793894 Share on other sites More sharing options...
lonewolf217 Posted March 25, 2009 Share Posted March 25, 2009 what data type is your time column in SQL ? also, I am not sure you need the single quotes around 'NOW()' Link to comment https://forums.phpfreaks.com/topic/151124-inserting-date-into-mysql-error-empty-string/#findComment-793895 Share on other sites More sharing options...
Z33M@N Posted March 25, 2009 Author Share Posted March 25, 2009 what data type is your time column in SQL ? also, I am not sure you need the single quotes around 'NOW()' Hi Lonewolf it doesn't really make a difference still the same. The data type is datetime, I also used timestamp before but no luck. Link to comment https://forums.phpfreaks.com/topic/151124-inserting-date-into-mysql-error-empty-string/#findComment-793903 Share on other sites More sharing options...
lonewolf217 Posted March 25, 2009 Share Posted March 25, 2009 one more thing I noticed. You are actually executing the query twice once from $result=mysql_query($sql); and once from if (!mysql_query($query)) try changing it to <? include('config.php'); // values sent from form $title=$_POST['title']; $description=$_POST['description']; $price=$_POST['price']; $town=$_POST['town']; $area=$_POST['area']; $category=$_POST['category']; $subcat=$_POST['subcat']; // Insert data into database $sql="INSERT INTO ads2(title, description, price, area, town, adDate, category, subcat)VALUES('$title', '$description', '$price', '$town','NOW()', '$area', '$category', '$subcat')"; echo $sql; $result=mysql_query($sql) or die('Error: ' . mysql_error()); // if suceesfully inserted data into database, send confirmation link to email echo "Thanks your ad was added!"; ?> Link to comment https://forums.phpfreaks.com/topic/151124-inserting-date-into-mysql-error-empty-string/#findComment-793949 Share on other sites More sharing options...
Z33M@N Posted March 26, 2009 Author Share Posted March 26, 2009 Thanks LoneWolf!!! Excellent works perfect. I did not realise I was call the $sql twice haha Thanks again for all your help one more thing I noticed. You are actually executing the query twice once from $result=mysql_query($sql); and once from if (!mysql_query($query)) try changing it to <? include('config.php'); // values sent from form $title=$_POST['title']; $description=$_POST['description']; $price=$_POST['price']; $town=$_POST['town']; $area=$_POST['area']; $category=$_POST['category']; $subcat=$_POST['subcat']; // Insert data into database $sql="INSERT INTO ads2(title, description, price, area, town, adDate, category, subcat)VALUES('$title', '$description', '$price', '$town','NOW()', '$area', '$category', '$subcat')"; echo $sql; $result=mysql_query($sql) or die('Error: ' . mysql_error()); // if suceesfully inserted data into database, send confirmation link to email echo "Thanks your ad was added!"; ?> Link to comment https://forums.phpfreaks.com/topic/151124-inserting-date-into-mysql-error-empty-string/#findComment-794231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.