Solved

default date value in input box

Posted on 2010-11-10
9
307 Views
Last Modified: 2012-08-13
Hi,

I have a querie that you can update after putting the date in the input box. Is there a way to put today's date by default in this box, but be able to change the date to a different date to override todays date?

Cheers
<form action="<?php echo $SCRIPT_NAME ?>" method="get">

Date:

<input size="10" type="text" name="today" value=<?PHP echo $today;?>>&nbsp;</input>





<A HREF="#" onClick="cal1x.select(document.forms[0].today,'anchor1x','dd-NNN-yyyy'); return false;" TITLE="Today" NAME="today" ID="anchor1x">

<IMG SRC="images/cal.JPG"></A>



<button value="Update" type="submit">Update</button>

</form>

Open in new window

0
Comment
Question by:Henk_du_Toit
  • 5
  • 4
9 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34105856
Try something like this:

<input size="10" type="text" name="today" value="<?php echo date('r'); ?>" />
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34105866
The ways of handling date and time strings are described in this article.  You may find it helpful.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Best regards, ~Ray
0
 

Author Comment

by:Henk_du_Toit
ID: 34105978
Hi Ray,

Thanks for your post. I know how to put today's date in by default. The only thing I am having trouble with is overriding when you change it on the web page.

<input size="10" type="text" name="today" value="<?php echo date('d-M-Y'); ?>" />

Doing this brings the default date like I want, but when I change the date to say last week on the web page, the value displayed stays as todays date.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34106031
Can you please post a more complete example of your code?  I think I can show you how to use a PHP variable to carry this information to the right places.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Henk_du_Toit
ID: 34106075
Attached is the code for the date and the query that uses the date.

Is this more or less what you wanted?
<SCRIPT LANGUAGE="JavaScript" ID="jscal1x">

     var cal1x = new CalendarPopup("testdiv1");

     cal1x.setCssPrefix("TEST");

     cal1x.showNavigationDropdowns();

     </SCRIPT>

<form action="<?php echo $SCRIPT_NAME ?>" method="get">

Date:

<input size="10" type="text" name="today" value=<?PHP echo $datum;?>>&nbsp;</input>





<A HREF="#" onClick="cal1x.select(document.forms[0].today,'anchor1x','dd-NNN-yyyy'); return false;" TITLE="Today" NAME="today" ID="anchor1x">

<IMG SRC="images/cal.JPG"></A>



<button value="Update" type="submit">Update</button>

</form>



<?php



	$cmdstrnw="select crep,brand,sum(gsales),sum(disc),sum(invsales),sum(pof),subtotalgsales,subtotaldisc,subtotalinvsales,subtotalpof,budget,subtotalbudget,crep1 from

(select a.crep as crep,a.brand as brand,

nvl(e.gsales,0) + nvl(b.gsales,0) + nvl(c.sale,0) as gsales,

nvl(e.disc,0) + nvl(b.disc,0) as disc,

nvl(e.invsales,0) + nvl(b.invsales,0) + nvl(c.sale,0) as invsales,

nvl(e.invsales,0) + nvl(b.invsales,0) + nvl(c.sale,0) - nvl(e.disc,0) - nvl(b.disc,0) - nvl(e.cogs,0) - nvl(b.cogs,0) as pof,

sum(nvl(e.gsales,0) + nvl(b.gsales,0) + nvl(c.sale,0)) over(partition by a.crep) as subtotalgsales,

sum(nvl(e.disc,0) + nvl(b.disc,0)) over(partition by a.crep) as subtotaldisc,

sum(nvl(e.invsales,0) + nvl(b.invsales,0) + nvl(c.sale,0)) over(partition by a.crep) as subtotalinvsales,

sum(nvl(e.invsales,0) + nvl(b.invsales,0) + nvl(c.sale,0) - nvl(e.disc,0) - nvl(b.disc,0) - nvl(e.cogs,0) - nvl(b.cogs,0)) over(partition by a.crep) as subtotalpof,

nvl(d.budget,0) as budget,

sum(nvl(d.budget,0)) over(partition by a.crep) as subtotalbudget,

a.crep1

from

(select a.nama as crep,a.brand as brand1,a.dsca as brand,a.crep as crep1

from brandl a) a

left join

(select crep,brand,sum(gsales) as gsales,sum(disc) as disc,sum(invsales) as invsales,sum(cogs) as cogs from(

    select e.t\$nama as crep,

    case when d.t\$cbrn = 'RETAIL' then d.t\$cbrn else brand.brand end as brand,

    sum(b.t\$damt/b.t\$rats$1) + sum(b.t\$amld/b.t\$rats$1) as gsales,

    sum(b.t\$amld/b.t\$rats$1) as disc,

    sum(b.t\$damt/b.t\$rats$1) as invsales,

    sum(b.t\$copr$1/b.t\$rats$1) as cogs

    from twhinh200099 a, ttdsls401099 b, twhinh220099 c, ttccom110099 d, ttccom001099 e, brand, ttcibd001099 f

    where a.t\$orno = b.t\$orno

    and a.t\$orno = c.t\$orno

    and d.t\$ofbp = a.t\$stco

    and e.t\$emno = d.t\$crep

    and b.t\$pono = c.t\$pono

    and a.t\$oset = c.t\$oset

    and f.t\$item = b.t\$item

    and f.t\$cpcl = brand.cpcl

    and b.t\$dltp <> '1'

    and b.t\$clyn <> '1'

    and d.t\$crep in ('NO','SO','CE','60','CON')

    and to_date(c.t\$addt + 0.54167) between to_date('$startw 00:00:00') and to_date('$today 23:59:59')

   group by e.t\$nama,d.t\$cbrn,brand.brand)

   group by crep,brand) e

on a.crep = e.crep

and a.brand1 = e.brand

left join

    (select crep,brand,sum(gsales) as gsales,sum(disc) as disc,sum(invsales) as invsales,sum(cogs) as cogs from(

    select e.t\$nama as crep,

    case when d.t\$cbrn = 'RETAIL' then d.t\$cbrn else brand.brand end as brand,

    sum(a.t\$damt/a.t\$rats$1) + sum(a.t\$amld/a.t\$rats$1) as gsales,

    sum(a.t\$amld/a.t\$rats$1) as disc,

    sum(a.t\$damt/a.t\$rats$1) as invsales,

    sum(a.t\$copr$1/a.t\$rats$1) as cogs

    from ttdsls401099 a, twhinh210099 b,twhinh200099 c,ttccom110099 d, ttccom001099 e,brand, ttcibd001099 f

    where a.t\$orno = b.t\$orno

    and a.t\$orno = c.t\$orno

    and d.t\$ofbp = c.t\$sfco

    and e.t\$emno = d.t\$crep

    and b.t\$pono = a.t\$pono

    and b.t\$oset = c.t\$oset

    and f.t\$item = a.t\$item

    and f.t\$cpcl = brand.cpcl

    and a.t\$dltp <> '1'

    and a.t\$clyn <> '1'

    and d.t\$crep in ('NO','SO','CE','60','CON')

    and to_date(b.t\$prdt + 0.54167) between to_date('$startw 00:00:00') and to_date('$today 23:59:59')

    group by e.t\$nama,d.t\$cbrn,brand.brand) 

    group by crep, brand) b

on a.crep = b.crep

and a.brand1 = b.brand

left join

  (select crep,brand,sum(sale) as sale from(

  select

	  ttccom001099.t\$nama as crep,

	  case when ttccom110099.t\$cbrn = 'RETAIL' then ttccom110099.t\$cbrn else brand.brand end as brand,

	  sum(tcisli225099.t\$amth$1/tcisli225099.t\$rate$1) as sale

	  from tcisli225099, tcisli220099,ttcibd001099,ttccom100099, ttccom110099, brand, ttccom001099

	  where tcisli225099.t\$item not like '%REBATE%'

	  and tcisli225099.t\$item not like '%PROMO%'

	  and tcisli225099.t\$item not like '%ZZ-1%'

	  and tcisli225099.t\$item not like '%ZZ-5%'

	  and tcisli225099.t\$item not like '%ZZ-6%'

	  and tcisli225099.t\$sfcp = tcisli220099.t\$sfcp

	  and tcisli225099.t\$msid = tcisli220099.t\$msid

	  and tcisli225099.t\$item = ttcibd001099.t\$item

	  and tcisli220099.t\$itbp = ttccom100099.t\$bpid

	  and tcisli220099.t\$ofbp = ttccom110099.t\$ofbp

	  and ttccom001099.t\$emno = ttccom110099.t\$crep

	  and ttcibd001099.t\$cpcl = brand.cpcl

	  and ttccom100099.t\$bpid = ttccom110099.t\$ofbp

	  and ttccom110099.t\$crep in ('NO','SO','CE','60','CON')

    and to_date(tcisli220099.t\$date + 0.54167) between to_date('$startw 00:00:00') and to_date('$today 23:59:59')

	  group by brand.brand,ttccom110099.t\$cbrn,ttccom001099.t\$nama)

    group by crep,brand)c

on c.crep = a.crep

and c.brand = a.brand1

left join

	(select crep,brand,sum(budget) as budget from (

  select b.t\$nama as crep,

    case when a.cata = 'C' then 'Branded' else 'Unbranded' end as brand,

    sum(a.budget) as budget

    from budgets a, ttccom001099 b

    where year = (SELECT CASE

                  WHEN TO_DATE('$startw 23:59:59') BETWEEN TO_DATE('$starty 00:00:00') AND add_months(TO_DATE('$endy 23:59:59'),-3)

                  THEN TO_NUMBER(TO_CHAR(TO_DATE('$startw 23:59:59'),'YYYY'))+ 1

                  ELSE TO_NUMBER(TO_CHAR(TO_DATE('$startw 23:59:59'),'YYYY')) END AS jaar FROM DUAL)

    and a.rep in ('NO','SO','CE','60','CON')

    and a.monnum = (SELECT CASE

                  WHEN TO_DATE('$startw 23:59:59') BETWEEN TO_DATE('$starty 00:00:00') AND add_months(TO_DATE('$endy 23:59:59'),-3)

                  THEN TO_NUMBER(TO_CHAR(TO_DATE('$startw 23:59:59'),'MM'))-3

                  ELSE TO_NUMBER(TO_CHAR(TO_DATE('$startw 23:59:59'),'MM'))+9 END AS jaar FROM DUAL) 

    and a.rep = b.t\$emno

    group by b.t\$nama, a.cata)

    group by crep,brand) d

on d.crep = a.crep

and d.brand = a.brand)

where (gsales <> 0

or budget <> 0)

group by crep,crep1,brand,subtotalgsales,subtotaldisc,subtotalinvsales,subtotalpof,subtotalbudget,budget

order by crep,brand

	";

$parsednw=ociparse($db_conn, $cmdstrnw);

ociexecute ($parsednw);

$nrowsnw=ocifetchstatement($parsednw, $resultsnw);

?>

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34106163
I'm not following this.  In the code you posted, $datum is an undefined variable.  You will get a Notice or a NULL value in the <input> control named "today".

You might also want to put quotes around the string in the value= attribute of the input tag.
0
 

Author Comment

by:Henk_du_Toit
ID: 34106202
Sorry I was playing around with it... $datum should be $today. It works perfectly, the only thing I want to achieve is to bring today's date up by default and be able to change it to any other date with that date being the new value of the input box..
0
 

Accepted Solution

by:
Henk_du_Toit earned 0 total points
ID: 34106442
I have fixed it. Thanks for your help anyway..

Attached is what I did to fix it
global $today;



if (isSet($_GET['today'])) {



$today	= $_GET['today'];

} else {

$today	= date('d-M-Y');

}

Open in new window

0
 

Author Closing Comment

by:Henk_du_Toit
ID: 34134703
I have found a solution myself.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
simplest php form 3 63
phpmyadmin 3 33
MySQL Grouping 2 23
A form to still have contents even if some are wrong 10 47
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now