why is this not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

why is this not working

Post 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
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: why is this not working

Post 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)));
?>
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: why is this not working

Post 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.
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: why is this not working

Post by Apollo »

What kinda variable type is this date field of yours? What happens if you try UNIX_TIMESTAMP() instead of NOW() ?
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: why is this not working

Post by nite4000 »

I believe its SOLVED If i have nay other trouble i know where to get help :wink:
Post Reply