Jump to content

concatenated php string into mysql


wev

Recommended Posts

here i am again...

 

so i have this algorithm that computes the current academic year for our school..

it outputs the correct academic year on a browser..

but when i try to insert it into my database, the data inserted goes wrong..

 

it just keeps on inserting -1 instead of the string 2011-2012

 

here's my code:

<?php

$year = date('Y');
$currentyear = $year;
$lastyear = $year - 1;
$nextyear = $year + 1;

if (date('m') < 6)
{
 $current_ay = $lastyear."-".$currentyear;
}
else
if (date('m') >= 6)
{
 $current_ay = $currentyear."-".$nextyear;
}

echo $current_ay;
  $insertSQL = "INSERT INTO tbl_elections (election_id) values ($current_ay)";

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

?>

 

 

*the database column to be inserted into is of varchar data type

 

Link to comment
https://forums.phpfreaks.com/topic/259362-concatenated-php-string-into-mysql/
Share on other sites

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.