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
Share on other sites

@david.. yes. my column name is correct..

 

@muddy_funster.. i did wrap it in quotes and it inserted a data into my database..but it only stored "2011". it did not include the "-2012"

 

 

--almost there!

 

Link to comment
Share on other sites

yeah..that's what i did..

figured out that the problem was with the datatype of the election_id column on my database..it was on int when it was supposed to be a varchar..

 

got it working now..thank you so much for your help.. :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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