Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hello

I have two requests that I need advice and help on.

 

1. I am trying to code a textfield only input that only accept characters instead of integers and special characters.

 

I was thinking of using ereg shown here.

           if (!ereg($letters, $Myname)) {
               echo Letters only required';
           }

Is there a better way of comparing characters using utf-8 or ASCII using one if statement rather than using separate if statements for integers and special characters.

 

2. I am trying to code a method that would update the date into a via button. So far I have coded this, however it is not working

 

<html>
   <head>
   </head>
   <body>
<?php
$submit = $_POST['submit'];
   if($submit){
      for ($i = 40; $i < 100; $i++) {
           $i = time() + ($i * 24 * 60 * 60);
   }
}
echo 'Next Week: ' . date('Y-m-d', $i) . "\n";
?>
<form>
  <input type="submit" name="submit" value="update"/>
  </form>
   </body>
</html> 

 

Some advice is grateful

 

Thank you

Link to comment
Share on other sites

Hi DeeDee,

 

With regards the second part - what exactly are you trying to achieve?

 

The code as it stands:

 

<html>
   <head>
   </head>
   <body>
<?php
$submit = $_POST['submit'];
   if($submit){
      for ($i = 40; $i < 100; $i++) {
           $i = time() + ($i * 24 * 60 * 60);
   }
}
echo 'Next Week: ' . date('Y-m-d', $i) . "\n";
?>
<form>
  <input type="submit" name="submit" value="update"/>
  </form>
   </body>
</html> 

 

  1. You have no method set in your form tag meaning it will default to GET rather than POST
  2. The echo statement is outside of the loop meaning it will only echo the next week line once
  3. 100 * 24 * 60 * 60 will be 100 days away not next week
  4. You can't redefine $i inside the loop else when it executes a second time it wont have the correct value

  • Upvote 1
Link to comment
Share on other sites

Hi DeeDee,

 

With regards the second part - what exactly are you trying to achieve?

 

The code as it stands:

 

<html>
   <head>
   </head>
   <body>
<?php
$submit = $_POST['submit'];
   if($submit){
      for ($i = 40; $i < 100; $i++) {
           $i = time() + ($i * 24 * 60 * 60);
   }
}
echo 'Next Week: ' . date('Y-m-d', $i) . "\n";
?>
<form>
  <input type="submit" name="submit" value="update"/>
  </form>
   </body>
</html> 

 

  1. You have no method set in your form tag meaning it will default to GET rather than POST
  2. The echo statement is outside of the loop meaning it will only echo the next week line once
  3. 100 * 24 * 60 * 60 will be 100 days away not next week
  4. You can't redefine $i inside the loop else when it executes a second time it wont have the correct value

 

Hi Stuart

To answer your question (and perhaps for other users as well) on what I am trying to acheive is to change the date via submit button that, when clicked is meant to go past the current date.

I hope this answers your question (oh btw the next week line is just a placement, in fact I just wanted to see the output of the date).

 

Thanks to all who so far replied. :)

Link to comment
Share on other sites

Still unsure as to what dates you want to output (how many? how far in the future?) but the code below is the basic principal:

 

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST'){

   for ($i = 1; $i < 11; $i++){

        $timestamp = time() + ($i * 24 * 60 * 60);
        echo '<p>' . date('Y-m-d', $timestamp) . '</p>';

   }

}

?>

<form method="post">
   <input type="submit" name="submit" value="Update" />
</form>

  • Upvote 1
Link to comment
Share on other sites

Still unsure as to what dates you want to output (how many? how far in the future?) but the code below is the basic principal:

 

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST'){

   for ($i = 1; $i < 11; $i++){

        $timestamp = time() + ($i * 24 * 60 * 60);
        echo '<p>' . date('Y-m-d', $timestamp) . '</p>';

   }

}

?>

<form method="post">
   <input type="submit" name="submit" value="Update" />
</form>

As much and as far as possible, in other words there is no limit. Oh and thank you for your help.

Link to comment
Share on other sites

No worries - that code there is outputting the next 10 days. By increasing the number it could produce any date up to 2038 - which is the limit for UNIX timestamps (that's still true as far as I know). If you wanted to output dates in the future you might also want to check out strtotime which allows for something like:

 

echo date('Y-m-d', strtotime('+ one week'));

Link to comment
Share on other sites

 Share

×
×
  • Create New...