Form to go with my html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chadbobb
Forum Newbie
Posts: 8
Joined: Mon Nov 08, 2004 8:27 pm

Form to go with my html

Post by chadbobb »

I got some help here a while ago and i got this below. I added a little bit to it to make it work with tables and stuff. But for some reason i can't get form to show up in wher i want them to. I keep getting an error that says
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/warren/public_html/whs/form template3.php on line 20
What do i need to just get a text box in one of those and a text area box?

thanks

Code: Select all

<table border="1" width="100%">
<FORM METHOD="POST" ACTION="mailto:your email address">
<tr>
<td width="25%">Date</td>
<td width=25% valign="top">&nbsp;</td>
<td width="50%">Assignment</td>
</tr>


<?php
$days=5;

function futureday($num_days_future)
{    for ($x=0; $x<$num_days_future; $x++)// loop through and add one day in seconds each time...
{
$numsec = 86400 * $x; //Multiply seconds by num_days_future
$nextday = time()+ $numsec; //Get Unix Time stamp
echo "<tr><td>" . date("j of F Y", $nextday) . "</td><td>I want a Form here</td><td>I want another form here</td></tr>";
}
}
futureday($days);

?>
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

if you want it to ouput some html there, just cut and paste the html in that location


you can echo over multiple lines like so

echo "

blah


blah
";

your parse error is likely because you did not escape double quotes like so

Code: Select all

echo "<form method="post">"; // parse error
echo "<form method="post">"; // correct, or use next method
echo '<form method="post">'; // works, notice using single quotes


// you can also drop out of php

function futureday($num_days_future)
{    for ($x=0; $x<$num_days_future; $x++)// loop through and add one day in seconds each time...
{
$numsec = 86400 * $x; //Multiply seconds by num_days_future
$nextday = time()+ $numsec; //Get Unix Time stamp
echo "<tr><td>" . date("j of F Y", $nextday);
?>

</td><td>I want a Form here</td><td>I want another form here</td></tr>
quotes dont matter if we drop out of php, because its directly output w/out parsing

<?php
}
}
chadbobb
Forum Newbie
Posts: 8
Joined: Mon Nov 08, 2004 8:27 pm

Post by chadbobb »

whoa. I think i kinda understood what you just said, but im still a php newb.

i figured out what you were saying.

Now i need help with something else, lol

I got help with the time stuff of it also a while back. what i want to do is also be able to go into negative days. Is there anyway i can do that without heavily moddifying it? i notice when i put in a negative sign that it will not go into the past like i want it to. How can i make it show stuff days from lets say 13 days ago?

Code: Select all

<html>

<table border="1" width="100%">
<FORM METHOD="POST" ACTION="mailto:your email address">
<tr>
<td width="25%">Date</td>
<td width=25% valign="top">&nbsp;</td>
<td width="50%">Assignment</td>
</tr>


<?php
$days=-21;

function futureday($num_days_future)
{    for ($x=0; $x<$num_days_future; $x++)// loop through and add one day in seconds each time...
{
$numsec = 86400 * $x; //Multiply seconds by num_days_future
$nextday = time()+ $numsec; //Get Unix Time stamp
echo "<tr><td>" . date("j of F Y", $nextday) . "</td><td><INPUT TYPE="text" NAME="name" SIZE="30"></td><td><TEXTAREA  NAME="comment" ROWS=2 valign="top" COLS="40"></TEXTAREA></td></tr>";
}
}
futureday($days);

?>

</table>

</html>
BTW thanks a bunch for the help
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

The reason it's not showing the negative days, is because of the first argument in the for loop:

syntax: for ( command at start of loop; condition check; command after every loop )

So, you're setting $x to 0, then checking that $x is less than -21 (which it's not).

I'd say, to do it right, change the function to have two arguments, one for the start date and one for the end date (both in days compared to the present), and use the start date to set $x at the start of the loop:

Code: Select all

<?php

$start = -21; // 21 days ago
$end = 14; // 14 days ahead

function days($start, $end) {
    for ($x = $start; $x <= $end; $x++) {
        $numsec = 86400 * $x; // Get the current time offset in seconds
        $nextday = time() + $numsec; // Get Unix timestamp
        echo '<tr><td>' . date("j of F Y", $nextday) . '</td><td><INPUT TYPE="text" NAME="name" SIZE="30"></td><td><TEXTAREA  NAME="comment" ROWS=2 valign="top" COLS="40"></TEXTAREA></td></tr>';
    }
}

days($start, $end); // call the function

?>
That said, if you're not planning on running the function more that once in order to get more than one get of rows etc (I doubt it), you don't need the function - you can just take out the function definition and the call, and just have the for loop.
Post Reply