Page 1 of 1

why is this not working

Posted: Mon Jun 06, 2011 5:38 pm
by nite4000
I am needing help why this isnt working with the NOW()

Code: Select all

$r=mysql_query("INSERT INTO investments(id,username,user_id,plan_id,plan_name,total_invest,rate,date,end_date,inv_date,reinvest)VALUES
(null,
'".$username."',
" . $id . ",
" . $plans . ",

'". $plan_details['plan_name'] . "',' " . $amount ."','" . $plan_details['percent'] . "',NOW(),


[b]" . "NOW() + INTERVAL " . $pack["invest_period"] . " DAY".",[/b]



NOW(),'$opt')")or die(mysql_error());
the part i put in bold wont work with the NOW() what that is doing is getting the date and then caculating a future date based on the length of the investment package.

if anyone can help me out thanks

its IMPORTANT

Re: why is this not working

Posted: Mon Jun 06, 2011 7:05 pm
by flying_circus
Have you tried DATE_ADD()?

Code: Select all

<?php
  $r = mysql_query(sprintf("INSERT INTO `investments` (`id`, `username`, `user_id`, `plan_id`, `plan_name`, `total_invest`, `rate`, `date`, `end_date`, `inv_date`, `reinvest`) VALUES (null, '%s', '%d', '%d', '%s', '%s', '%s', NOW(), DATE_ADD(NOW(), INTERVAL '%d' DAY), NOW(), '%d');",
                         mysql_real_escape_string($username),
                         mysql_real_escape_string($id),
                         mysql_real_escape_string($plans),
                         mysql_real_escape_string($plan_details['plan_name']),
                         mysql_real_escape_string($amount),
                         mysql_real_escape_string($plan_details['percent']),
                         mysql_real_escape_string($pack["invest_period"]),
                         mysql_real_escape_string($opt)));
?>

Re: why is this not working

Posted: Tue Jun 07, 2011 6:09 am
by nite4000
yeah i just tried that as you said but its not giving the date correctly it should be a future dat that is where the + INTERVAL come in at on my other code.

Re: why is this not working

Posted: Tue Jun 07, 2011 6:23 am
by Apollo
What kinda variable type is this date field of yours? What happens if you try UNIX_TIMESTAMP() instead of NOW() ?

Re: why is this not working

Posted: Tue Jun 07, 2011 9:20 am
by nite4000
I believe its SOLVED If i have nay other trouble i know where to get help :wink: