Forums
This topic is locked
add to current date
Posted 16 Dec 2006 08:47:17
1
has voted
16 Dec 2006 08:47:17 Bill Brandes posted:
Hi,I have this code that I am trying to add months or a year to the current date. The first code works fine until i add the addtional code to add to the current date.
<?php
$con = mysql_connect("localhost","user","password"
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("comersus", $con);$sql="INSERT INTO seattle (CompanyName, ContactTitle, Address, City, PostalCode, State, StateID, Phone, CatID, CatDescription, Email, URL, Des, ebizcard, Duration, DateSubmit)
VALUES
('$_POST[CompanyName]','$_POST[ContactTitle]','$_POST[Address]','$_POST[City]','$_POST[PostalCode]','$_POST[State]','$_POST[State]','$_POST[Phone]','$_POST[CatID]','$_POST[CatDescription]','$_POST[Email]','$_POST[URL]','$_POST[Des]','$_POST[ebizcard]','$_POST[duration]', CURDATE() )";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_close($con)
?>
The following code with the add to current date gets this error: Parse error: parse error, unexpected T_STRING in c:\Inetpub\vhosts\mydomain.com\httpdocs\insert5.php on line 8
<?php
$con = mysql_connect("localhost","user","password"
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if ( $duration == "3" ) {
$DATE_ADD = (CURDATE() + 3 MONTHS);
}
if ( $duration == "6" ) {
$DATE_ADD = (CURDATE() + 6 MONTHS);
}
if ( $duration == "12" ) {
$DATE_ADD = (CURDATE() + 1 YEAR);
}
mysql_select_db("comersus", $con);$sql="INSERT INTO seattle (CompanyName, ContactTitle, Address, City, PostalCode, State, StateID, Phone, CatID, CatDescription, Email, URL, Des, ebizcard, Duration, DateSubmit, DatePaid, DateExp)
VALUES
('$_POST[CompanyName]','$_POST[ContactTitle]','$_POST[Address]','$_POST[City]','$_POST[PostalCode]','$_POST[State]','$_POST[State]','$_POST[Phone]','$_POST[CatID]','$_POST[CatDescription]','$_POST[Email]','$_POST[URL]','$_POST[Des]','$_POST[ebizcard]','$_POST[duration]', CURDATE(),'$_POST[null]', DATE_ADD )";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_close($con)
?>
Any help would be apprecated.
Thanks,
Bill
Edited by - gibsongk55 on 16 Dec 2006 14:15:29
Replies
Replied 19 Dec 2006 17:50:55
19 Dec 2006 17:50:55 Roddy Dairion replied:
Ok this should do the trick its the second part of code the add date
<pre id=code><font face=courier size=2 id=code>
<?php
$con = mysql_connect("localhost","user","password"
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if ( $duration == "3" ) {
$DATE_ADD = "date_add(curdate(), interval 3 month)";
}
if ( $duration == "6" ) {
$DATE_ADD = "date_add(curdate(), interval 6 month)";
}
if ( $duration == "12" ) {
$DATE_ADD = "date_add(curdate(), interval 12 month)";
}
mysql_select_db("comersus", $con);$sql="INSERT INTO seattle (CompanyName, ContactTitle, Address, City,
PostalCode, State, StateID, Phone, CatID, CatDescription, Email, URL, Des, ebizcard, Duration, DateSubmit, DatePaid, DateExp)
VALUES
('$_POST[CompanyName]','$_POST[ContactTitle]','$_POST[Address]','$_POST[City]','$_POST[PostalCode]','$_POST[State]','$_POST[State]',
'$_POST[Phone]','$_POST[CatID]','$_POST[CatDescription]','$_POST[Email]','$_POST[URL]','$_POST[Des]','$_POST[ebizcard]',
'$_POST[duration]', CURDATE(),'$_POST[null]', $DATE_ADD )";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_close($con)
?>
</font id=code></pre id=code>
Edited by - roders22 on 19 Dec 2006 17:51:35
<pre id=code><font face=courier size=2 id=code>
<?php
$con = mysql_connect("localhost","user","password"
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if ( $duration == "3" ) {
$DATE_ADD = "date_add(curdate(), interval 3 month)";
}
if ( $duration == "6" ) {
$DATE_ADD = "date_add(curdate(), interval 6 month)";
}
if ( $duration == "12" ) {
$DATE_ADD = "date_add(curdate(), interval 12 month)";
}
mysql_select_db("comersus", $con);$sql="INSERT INTO seattle (CompanyName, ContactTitle, Address, City,
PostalCode, State, StateID, Phone, CatID, CatDescription, Email, URL, Des, ebizcard, Duration, DateSubmit, DatePaid, DateExp)
VALUES
('$_POST[CompanyName]','$_POST[ContactTitle]','$_POST[Address]','$_POST[City]','$_POST[PostalCode]','$_POST[State]','$_POST[State]',
'$_POST[Phone]','$_POST[CatID]','$_POST[CatDescription]','$_POST[Email]','$_POST[URL]','$_POST[Des]','$_POST[ebizcard]',
'$_POST[duration]', CURDATE(),'$_POST[null]', $DATE_ADD )";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_close($con)
?>
</font id=code></pre id=code>
Edited by - roders22 on 19 Dec 2006 17:51:35
Replied 19 Dec 2006 19:28:50
19 Dec 2006 19:28:50 Bill Brandes replied:
Hi Roddy,
Thanks for the help but still not working. No errors, but the DateExp field is empty (DATE_ADD)
Here is the code again as it now stands:
<?php
$con = mysql_connect("localhost","user","password"
$nFlag=="N";
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//everything working now except Date expiration field still empty
if ( $duration == "3" ) {
$DATE_ADD = "date_add(curdate(), interval 3 month)";
}
if ( $duration == "6" ) {
$DATE_ADD = "date_add(curdate(), interval 6 month)";
}
if ( $duration == "12" ) {
$DATE_ADD = "date_add(curdate(), interval 12 month)";
}
mysql_select_db("comersus", $con);$sql="INSERT INTO seattle (CompanyName, ContactTitle, Address, City, PostalCode, State, StateID, Phone, CatID, CatDescription, Email, URL, Des, nFlag, BillingType, ebizcard, Duration, DateSubmit, DatePaid, DateExp)
VALUES
('$_POST[CompanyName]','$_POST[ContactTitle]','$_POST[Address]','$_POST[City]','$_POST[PostalCode]', State ,'$_POST[StateID]','$_POST[Phone]','$_POST[CatID]','$_POST[CatDescription]','$_POST[Email]','$_POST[URL]','$_POST[Des]', nFlag ,'$_POST[listing_type]','$_POST[ebizcard]','$_POST[duration]', CURDATE(),'$_POST[DatePaid]', '$DATE_ADD' )";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_close($con)
?>
Edited by - gibsongk55 on 20 Dec 2006 03:54:16
Thanks for the help but still not working. No errors, but the DateExp field is empty (DATE_ADD)
Here is the code again as it now stands:
<?php
$con = mysql_connect("localhost","user","password"
$nFlag=="N";
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//everything working now except Date expiration field still empty
if ( $duration == "3" ) {
$DATE_ADD = "date_add(curdate(), interval 3 month)";
}
if ( $duration == "6" ) {
$DATE_ADD = "date_add(curdate(), interval 6 month)";
}
if ( $duration == "12" ) {
$DATE_ADD = "date_add(curdate(), interval 12 month)";
}
mysql_select_db("comersus", $con);$sql="INSERT INTO seattle (CompanyName, ContactTitle, Address, City, PostalCode, State, StateID, Phone, CatID, CatDescription, Email, URL, Des, nFlag, BillingType, ebizcard, Duration, DateSubmit, DatePaid, DateExp)
VALUES
('$_POST[CompanyName]','$_POST[ContactTitle]','$_POST[Address]','$_POST[City]','$_POST[PostalCode]', State ,'$_POST[StateID]','$_POST[Phone]','$_POST[CatID]','$_POST[CatDescription]','$_POST[Email]','$_POST[URL]','$_POST[Des]', nFlag ,'$_POST[listing_type]','$_POST[ebizcard]','$_POST[duration]', CURDATE(),'$_POST[DatePaid]', '$DATE_ADD' )";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_close($con)
?>
Edited by - gibsongk55 on 20 Dec 2006 03:54:16
Replied 20 Dec 2006 10:50:04
20 Dec 2006 10:50:04 Roddy Dairion replied:
Whats $duration??
Replied 20 Dec 2006 16:05:16
20 Dec 2006 16:05:16 Bill Brandes replied:
$duration is a field that is posted from the form with a value of either "3", "6", or "12" as in months. So depending on what the duration
value is, that is the amount of time in months I need to add to the current date to get an expiration date or $DateExp.
Thanks,
Bill
value is, that is the amount of time in months I need to add to the current date to get an expiration date or $DateExp.
Thanks,
Bill
Replied 20 Dec 2006 16:44:42
20 Dec 2006 16:44:42 Roddy Dairion replied:
well where is it declared in your script?
Replied 20 Dec 2006 16:53:48
20 Dec 2006 16:53:48 Bill Brandes replied:
it gets passed from the script that calls this script
Replied 20 Dec 2006 17:21:33
20 Dec 2006 17:21:33 Roddy Dairion replied:
Can you please send all of the scripts that you have for this?? Thx.