Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 14th, 2005, 12:13 PM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help On Creating a Script

Hello

I am new in php and i want to ask you something

I want to create a script that the admin will choose a date e.x 12 December 2005

and click sumbit and show him the result only for 12 december 2005

I have created the arrays for day month and year and i want now someone to help me how i can add the things that i told you before

This is the code that i have written :



<html>

<head>
  <title></title>
</head>

<body>

<?php
/* Program name: report.php
* Description: Program displays a selection list that
* customers can use to select a date.
*/
$link = mysql_connect("mysql_host", "mysql_login", "mysql_password")
  or die ("Could not connect to MySQL");

mysql_select_db ("my_database")
  or die ("Could not select database");
echo "<html>
<head><title>Select a date</title></head>
<body>";
/* create an array of months*/
$monthName = array(1=> "January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December");
$today = time(); //stores today's date
$f_today = date("M-d-Y",$today); //formats today's date
echo "<div align='center'>\n";
/* display today's date */
echo "<p>&nbsp;<h3>Today is $f_today</h3>\n";
/* create form containing date selection list */
echo "<form action='processform.php' method='POST'>\n";
/* build selection list for the month */
$todayMO = date("m",$today); //get the month from $today
echo "<select name='dateMO'>\n";
for ($n=1;$n<=12;$n++)
{
echo "<option value=$n\n";
if ($todayMO == $n)
{
echo " selected";
}
echo "> $monthName[$n]\n";
}
echo "</select>";
/* build selection list for the day */
$todayDay= date("d",$today); //get the day from $today
echo "<select name='dateDay'>\n";
for ($n=1;$n<=31;$n++)
{
echo " <option value=$n";
if ($todayDay == $n )
{
echo " selected";
}
echo "> $n\n";
}
echo "</select>\n";
/* build selection list for the year */
$startYr = date("Y", $today); //get the year from $today
echo "<select name='dateYr'>\n";
for ($n=$startYr;$n<=$startYr+1;$n++)
{
echo " <option value=$n";
if ($startYr == $n )
{
echo " selected";
}
echo "> $n\n";
}
echo "</select>\n";
echo "</form>\n";

?>
</body>

</html>


Reply With Quote
  #2 (permalink)  
Old December 15th, 2005, 02:16 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: South San Francisco, CA, USA.
Posts: 128
Thanks: 0
Thanked 1 Time in 1 Post
Default

First you need to add a submit input type on your form:
<input type="submit" name="submit" value="submit">
Then you need php file name processform.php. and
have a script that will check if submit button was clicked:
if (!(array_key_exists('submit', $_POST)))
{
  // This will redirect back to the form
  echo "This will redirect back to the form";
  header (Location: URL where the above form is located);
  exit();
}
else
{
  // validate each form input if there are values submitted.
  // for example:
  $dateMo = $_POST['dateMo'];
  if (!isset($dateMo))
  {
    $mm = false;
  }
  else
  {
    $mm = true;
  }

  $dateDay = $_POST['dateDay'];
  if (!isset($dateDay))
  {
    $dd = false;
  }
  else
  {
    $dd = true;
  }

  $dateYr = $_POST['dateYr'];
  if (!isset($dateYr))
  {
    $yy = false;
  }
  else
  {
    $yy = true;
  }

  // All should be true
  if ( $mm && $dd && $yy )
  {
    // Process script to retreive data from the database.
  }


}

Hope this helps.
jmaronilla



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 11 creating a user reg script ed123 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 September 28th, 2007 11:36 AM
Need help with Creating Procedures Script in SQL Rrotz BOOK: Professional DotNetNuke ASP.NET Portals ISBN: 0-7645-9563-6 0 November 1st, 2006 12:41 AM
creating tables using sql script -howto? qwjunk SQL Server 2000 0 August 24th, 2004 09:42 AM
Call and run CGI script from a PHP script ... how? dbruins BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 June 10th, 2003 03:09 PM



All times are GMT -4. The time now is 12:45 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.