Jump to content

insert a varchar data into mysql from a php date() function


wev

Recommended Posts

hi there..im new to php mysql and im having trouble inserting a string data to mysql from a php date() function.

 

 

here's my code:

 $year = date('Y');
echo $year;
  $insertSQL = sprintf("INSERT INTO tbl_elections (election_id=$year)");

  mysql_select_db($database_organizazone_db, $organizazone_db);
  $Result1 = mysql_query($insertSQL, $organizazone_db) or die(mysql_error());

 

when i try to output the $year variable on a webpage, it returns "2012"

but when i try to insert this data into my database table, it returns an error like this:

 

check the manual that corresponds to your MySQL server version for the right syntax to use near '=2012)'

 

is there a way to convert "2012" into a normal string data type?

$year = date('Y');
echo $year;
  $insertSQL = "INSERT INTO tbl_elections (election_id) values ($year)";

  mysql_select_db($database_organizazone_db, $organizazone_db);
  $Result1 = mysql_query($insertSQL, $organizazone_db) or die(mysql_error());

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.