Jump to content

Inserting date into Mysql error: empty string


Z33M@N

Recommended Posts

Hi guys I'm new here  ;D

 

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

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!";

?> 

Thanks LoneWolf!!! Excellent works perfect. I did not realise I was call the $sql twice haha ;D

 

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!";

?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.