...

View Full Version : I am GOING Round In Circles! STILL MY DATE DOES NOT WORK PROPERLY!!



Byronwells
02-04-2010, 03:42 PM
Alright Coders

This is really getting furstating me... I have been on this same issue for quite a few days now, and everything that I try does not seem to solve it.. I feel like chucking my computer out...

I am using a php membership script. In the admin area, add_products.html
I have added a javascript datepicker which is linked to a text box. The name of this text box is called product_date

On the add_product.php page which links to the above page I have added the two following pieces of code

In admin/add_product php after the line " $prod_description = addslashes($_POST["prod_description"]);" add the line " $prod_date = date("Y-m-d", strtotime($_POST["date"]));"


Then, after the line "$set .= "category = '$category',";" add the line " $set .= "prod_date = '$prod_date',";" where "prod_date" is the name of the date field in the products table (if you're using a different name just change "prod_date" accordingly).

full code


<?php

include "session.php" ;
include "header.php" ;

$GetFile = file("../html/admin/add_product.html");
$Content = join("", $GetFile);

function encodeHTML($sHTML)
{
$sHTML=ereg_replace("&","&amp;",$sHTML);
$sHTML=ereg_replace("<","&lt;",$sHTML);
$sHTML=ereg_replace(">","&gt;",$sHTML);
return $sHTML;
}



if (isset($_POST['submit']))
{
// Clean up form data
$product_name = addslashes($_POST["product_name"]);
$pshort = $_POST["pshort"];
$price = $_POST["price"];
$commission = $_POST["commission"];
$jv_commission = $_POST["jv_commission"];
$index_page = addslashes($_POST["index_page"]);
$download_form = addslashes($_POST["download_form"]);
$price_increase = $_POST["price_increase"];
$increase = $_POST["increase"];
$price_interval = $_POST["price_interval"];
$increase_finish = $_POST["increase_finish"];
$home_page_product = $_POST["home_page_product"];
$use_headers = $_POST["use_headers"];
$limit_members = $_POST["limit_members"];
$reset = $_POST["reset"];
$member_cap = $_POST["member_cap"];
$membershipcap = addslashes($_POST["membershipcap"]);
$points_on = $_POST["points_on"];
$points_req = $_POST["points_req"];
$pp_button = $_POST["pp_button"];
$pptext = addslashes($_POST["pptext"]);
$ppbutton = addslashes($_POST["ppbutton"]);
$show_product = $_POST["show_product"];
$get_affurl = $_POST["get_affurl"];
$licence = $_POST["licence"];
$subscription_active = $_POST["subscription_active"];
$period1_active = $_POST["period1_active"];
$period1_value = $_POST["period1_value"];
$period1_interval = $_POST["period1_interval"];
$srt = $_POST["srt"];
$amount1 = $_POST["amount1"];
$period2_active = $_POST["period2_active"];
$period2_value = $_POST["period2_value"];
$period2_interval = $_POST["period2_interval"];
$amount2 = $_POST["amount2"];
$period3_value = $_POST["period3_value"];
$period3_interval = $_POST["period3_interval"];
$psponder = $_POST["psponder"];
$category = $_POST["category"];
$tcontent = $_POST["tcontent"];
$amount3 = $_POST["amount3"];
$dl_loc = $_POST["dl_loc"];
$offsite = addslashes($_POST["offsite"]);
$imageurl = $_POST["imageurl"];
$prod_description = addslashes($_POST["prod_description"]);
$product_date = date("Y-m-d", strtotime($_POST["_product_date"]));


if ($home_page_product=='1')
{
$set = "home_page_product = '0'";
$db->insert("update ".$prefix."products set $set");
$home_page_product = "1";
}

$set = "product_name = '$product_name',";
$set .= "pshort ='$pshort',";
$set .= "price = '$price',";
$set .= "commission = '$commission',";
$set .= "jv_commission = '$jv_commission',";
$set .= "index_page = '$index_page',";
$set .= "download_form = '$download_form',";
$set .= "price_increase = '$price_increase',";
$set .= "increase = '$increase',";
$set .= "price_interval = '$price_interval',";
$set .= "increase_finish = '$increase_finish',";
$set .= "home_page_product = '$home_page_product'," ;
$set .= "use_headers ='$use_headers',";
$set .= "main_product ='$main_product',";
$set .= "limit_members ='$limit_members',";
$set .= "reset ='$reset',";
$set .= "member_cap = '$member_cap',";
$set .= "membershipcap = '$membershipcap',";
$set .= "points_on ='$points_on',";
$set .= "points_req ='$points_req',";
$set .= "pp_button ='$pp_button',";
$set .= "pptext = '$pptext',";
$set .= "ppbutton = '$ppbutton',";
$set .= "show_product ='$show_product',";
$set .= "get_affurl ='$get_affurl',";
$set .= "licence = '$licence',";

$set .= "subscription_active = '$subscription_active',";
$set .= "period1_active = '$period1_active',";
$set .= "period1_value = '$period1_value',";
$set .= "period1_interval = '$period1_interval',";
$set .= "srt = '$srt',";
$set .= "amount1 = '$amount1',";
$set .= "period2_active = '$period2_active',";
$set .= "period2_value = '$period2_value',";
$set .= "period2_interval = '$period2_interval',";
$set .= "amount2 = '$amount2',";
$set .= "period3_value = '$period3_value',";
$set .= "period3_interval = '$period3_interval',";
$set .= "amount3 = '$amount3',";
$set .= "psponder = '$psponder',";
$set .= "tcontent = '$tcontent',";
$set .= "dl_loc = '$dl_loc',";
$set .= "imageurl = '$imageurl',";
$set .= "prod_description = '$prod_description',";
$set .= "category = '$category',";
$set .= "offsite = '$offsite'";
$set .= "product_date = '$product_date',";

$pid = $db->insert_data_id("insert into ".$prefix."products set $set") ;
$msg = "add";
header("Location: paid_products.php?msg=$msg");
}

$q = "select * from ".$prefix."category order by cat_name";
$r = $db->get_rsltset($q);
for ($i=0; $i < count($r); $i++)
{
@extract($r[$i]);
$pid = $cat_name;

if($pid ==$showcat)
{
$category.="<option value='$pid' Selected>$pid</option>";
}
elseif($pid !=$showcat)
{
$category.="<option value='$pid'>$pid</option>";
}
}


$q = "select * from ".$prefix."responders order by rspname2";
$r = $db->get_rsltset($q);

for ($i=0; $i < count($r); $i++)
{
@extract($r[$i]);
$pid = $rspname2;

if($pid ==$showpaid)
{
$psponder.="<option value='$pid' Selected>$pid</option>";
}
elseif($pid !=$showpaid)
{
$psponder.="<option value='$pid'>$pid</option>";
}
}
$q = "select * from ".$prefix."tccampaign order by shortname";
$r = $db->get_rsltset($q);
for ($i=0; $i < count($r); $i++)
{
@extract($r[$i]);
$pid = $shortname;

if($pid ==$showtimed)
{
$tcontent.="<option value='$pid' Selected>$pid</option>";
}
elseif($pid !=$showtimed)
{
$tcontent.="<option value='$pid'>$pid</option>";
}
}


$Content = preg_replace($Ptn,"$$1",$Content);
echo $Content;

include "footer.php";
?>



The product_date text box with the two pieces of code is suppose to link to db field called product_date with the date type yyyy-mm-dd

But now I get this error message when I submit the product to the datebase

error message
insert into smp_products set product_name = 'Whatever',pshort ='',price = '',commission = '',jv_commission = '',index_page = '
',download_form = '
',price_increase = '0',increase = '',price_interval = '',increase_finish = '',home_page_product = '0',use_headers ='0',main_product ='',limit_members ='0',reset ='',member_cap = '',membershipcap = '
',points_on ='0',points_req ='',pp_button ='0',pptext = '',ppbutton = '',show_product ='1',get_affurl ='0',licence = 'Basic Resale Rights',subscription_active = '',period1_active = '',period1_value = '',period1_interval = 'D',srt = '',amount1 = '',period2_active = '',period2_value = '',period2_interval = 'D',amount2 = '',period3_value = '',period3_interval = 'D',amount3 = '',psponder = '0',tcontent = '0',dl_loc = '0',imageurl = '',prod_description = '',category = 'Dec 2008',offsite = ''product_date = '1969-12-31', 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'product_date = '1969-12-31',' at line 1

I really need help on this big time.. I can not move on until this sorted.. I know that I need to tell the date that is stored in the text box on the add_product.html page to be stored in the actual db field in the right format.. But nothing that I dont will work.

The way the date is enter in the text box is as follows mm-dd-yyyy. That cant not be changed because it is automatic from the datepicker that I am using..

Dormilich
02-04-2010, 03:48 PM
there’s a comma after the product date. that’s not allowed at the end of a SQL string.

Byronwells
02-04-2010, 04:01 PM
thereís a comma after the product date. thatís not allowed at the end of a SQL string.

Ok I have taken the comma out of the this line
$set .= "product_date = '$product_date'";

But I am still getting this error

insert into smp_products set product_name = 'howdy',pshort ='',price = '',commission = '',jv_commission = '',index_page = '
',download_form = '
',price_increase = '0',increase = '',price_interval = '',increase_finish = '',home_page_product = '0',use_headers ='0',main_product ='',limit_members ='0',reset ='',member_cap = '',membershipcap = '
',points_on ='0',points_req ='',pp_button ='0',pptext = '',ppbutton = '',show_product ='1',get_affurl ='1',licence = 'Basic Resale Rights',subscription_active = '',period1_active = '',period1_value = '',period1_interval = 'D',srt = '',amount1 = '',period2_active = '',period2_value = '',period2_interval = 'D',amount2 = '',period3_value = '',period3_interval = 'D',amount3 = '',psponder = '0',tcontent = '0',dl_loc = '0',imageurl = '',prod_description = '',category = 'Dec 2008',offsite = ''product_date = '1969-12-31' 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'product_date = '1969-12-31'' at line 1


Also if you have a look at the other sets, they have got a comma which doesnt effect nothing

tomws
02-04-2010, 04:04 PM
offsite = '',product_date = '1969-12-31'

Byronwells
02-04-2010, 04:06 PM
offsite = '',product_date = '1969-12-31'

Alright Tom

Can you just confirm that you want me to change this code

$set .= "offsite = '$offsite'";

To the above code?

Or am I mistaken please?

tomws
02-04-2010, 04:08 PM
Yes. You're missing the comma at the end of the offsite pair.

Byronwells
02-04-2010, 04:22 PM
Yes. You're missing the comma at the end of the offsite pair.

Tom
Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you

Byronwells
02-04-2010, 04:27 PM
Yes. You're missing the comma at the end of the offsite pair.

Tom

I dont suppose I could trouble you for some help?? :) :)

If you dont mind taking a look at this page.. You will now see due to your brilliant help the date is being display.. http://www.digitalresellersvault.com/marketplace.php?cat=t&category=Dec_2008

I was wondering two things please.. Let me do one thing at the time.. I have now got the date to be stored in the right format. However, can I change the format of the way it is displayed? So that the output is as follows.. mm-dd-yyyy please?

Byronwells
02-04-2010, 04:34 PM
Yes. You're missing the comma at the end of the offsite pair.

Alright Tom

Something is not quite right at the moment...

I add a product call monkey with the date 02/04/2010 but it is showing up as
1969-12-31

Same with the product underneath...

Any ideas please??

tomws
02-04-2010, 04:41 PM
1969-12-31 is the zero of dates. When you see that, it means your variable value is 0, null, empty, or another equivalent which is being cast as a date. That's happening here:

$product_date = date("Y-m-d", strtotime($_POST["_product_date"]));

Your post variable's value there is probably not what's expected. Dump it and check. Modify as necessary.

Byronwells
02-04-2010, 04:50 PM
1969-12-31 is the zero of dates. When you see that, it means your variable value is 0, null, empty, or another equivalent which is being cast as a date. That's happening here:

$product_date = date("Y-m-d", strtotime($_POST["_product_date"]));

Your post variable's value there is probably not what's expected. Dump it and check. Modify as necessary.

Tom got that to work now :) ta

See here
http://www.digitalresellersvault.com/marketplace.php?cat=t&category=Master_Resale_Rights

can you help me with my other question? :D:D

tomws
02-04-2010, 04:56 PM
If you're storing the date as you should be (date or datetime field), change the query to select the date with date_format (http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format). If it's being stored incorrectly as a string, use a combo back on the php side of mktime/strtotime and date.

Byronwells
02-04-2010, 04:59 PM
If you're storing the date as you should be (date or datetime field), change the query to select the date with date_format (http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format). If it's being stored incorrectly as a string, use a combo back on the php side of mktime/strtotime and date.

Tom

Now you have lost me.. lol.. Change what query??

tomws
02-04-2010, 05:04 PM
Whatever query is pulling the item list.

Byronwells
02-04-2010, 05:08 PM
Whatever query is pulling the item list.

You mean the piece of code that I am using to display the date on that page correct??

You mean this code



$product_date = $r[product_date];


Taken from the above marketplace.php code which displays the page that I showed you




<?php
include_once ("header.php");
$cat = $_GET["cat"];
$link = $_GET["category"];
$search = $_GET["search"];
$cat_title = str_replace("_"," ",$link);

if($cat != "t")
{
$GetFile = file("http://www.digitalresellersvault.com/template/template.php");
$Content = join("", $GetFile);
$categories=$common->categories($db);
$content=str_replace("{categories}",$categories,$content);
$Pat = "/<{Begin}>(.*?)<{End}>/s";
preg_match($Pat,$Content,$Output);
$SelectedContent = $Output[1];
$q = "select * from ".$prefix."products where show_product = '1' ORDER BY Rand() LIMIT 1";
$r = $db->get_a_line($q);
$id = $r[id];
$imageurl = $r[imageurl];
$prod_description = $r[prod_description];
$salesprice = $r[price];
$product_name = $r[product_name];
$licence = $r[licence];
$product_date = $r[product_date];
$salespage_link='<a href="prods.php?pid='.$id.'"><img border="0" src="http://www.digitalresellersvault.com/template/images/moreinfobutton.jpg" width="104" height="16"></a>';


$prod_image ='<img src="images/'.$imageurl.'" border="0">';

$Content = preg_replace($Pat,$ToReplace,$Content);
$Content = preg_replace("/{{(.*?)}}/e", "$$1", $Content);
echo $Content;
include_once ("footer.php");
exit();
}


elseif($cat == "t")
{
$search = $_GET["search"];
$link = $_GET["category"];
$cat_title = str_replace("_"," ",$link);
$GetFile = file("http://www.digitalresellersvault.com/template/template.php");
$Content = join("", $GetFile);
$categories=$common->categories($db);
$content=str_replace("{categories}",$categories,$content);
$theselect=$common->category_select($db, 'select');
$Content = str_replace("{{category_select}}", $theselect, $Content);

$Pat = "/<{Begin}>(.*?)<{End}>/s";
preg_match($Pat,$Content,$Output);
$SelectedContent = $Output[1];

if($search_txt != "")
{
$cond = "where product_name like '%".$search_txt."%' && show_product = '1'";
}
else
{
$cond = "where category = '$cat_title' && show_product = '1'";
}

########## pagination ###########
$q = "select count(*) as cnt from ".$prefix."products $cond";
$r = $db->get_a_line($q);
$count = $r[cnt];
if($count == "0")
{
$warning = "No Results Found";
}
$records=10;
$links="marketplace.php?cat=t&category=$link&search_txt=$search_txt&";

if($page=="")
{
$page=1;
}
$start=($page-1)*$records;
$Content=$common->print_page_break3($db,$Content,$count,$records,$links,$page);
########## pagination ###########

$ChangeColor = 1;
$ToReplace = "";
$GetProduct = $db->get_rsltset("select * from ".$prefix."products $cond order by id DESC limit $start, $records");
for($i = 0; $i < count($GetProduct); $i++)
{
$bgcolor = "#FFFFFF";
@extract($GetProduct[$i]);
if($period3_interval == "D"){$interval = "Day(s)";}
if($period3_interval == "W"){$interval = "Week(s)";}
if($period3_interval == "M"){$interval = "Month(s)";}
if($period3_interval == "Y"){$interval = "Year(s)";}

if($subscription_active == "1")
{
$salesprice = $amount3." every ".$period3_value." ".$interval;
}
else
{
$salesprice = $price;
}
$prod_image ='<img src="images/'.$imageurl.'" border="0"width="140" height="140">';
$salespage_link='<a href="prods.php?pid='.$id.'"><img border="0" src="http://www.digitalresellersvault.com/template/images/moreinfobutton.jpg" width="104" height="16"></a>';
$ToReplace .= preg_replace($Ptn,"$$1",$SelectedContent);
}
}

$Content = preg_replace($Pat,$ToReplace,$Content);
$Content = preg_replace("/{{(.*?)}}/e", "$$1", $Content);
echo $Content;
include_once ("footer.php");
?>


Or am I getting totally confused??



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum