RE: Php if statement in a form

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks Eric,

I have changed it somewhat but am just getting a parse error,
unexpected T_STRING on that line.

My revised code is below:


print "<b>Current Staff Working Alone</b>";
print "</td></tr>";
print "</table>\n";
print "<table border=\"1\" cellpadding=\"3\" cellspacing=\"0\">\n";
print
"<tr><td></td><td><b>Name</b></td><td><b>Location</b></td><td><b>Time
in</b></td><td><b>Time Out</b></td>/tr>";
while ($row = mysql_fetch_array($result, MYSQL_BOTH))
{
    print "<tr><td>";
    print "<INPUT TYPE='RADIO' NAME='id' VALUE='".$row["id"]."'>";
    print "</td><td>";
    print $row["name"];
    print "</td><td>";
    print $row["location"];
    print "</td><td>";
    print $row["timein"];
    print "</td><td>";
    if ($row["timeout"] IS NULL);
    {
    print <input name="timeout" type="text" value="echo date('H:i')">;
    } else {
    print $row["timeout"];
    }
    print "</td></tr>\n";
    }
    print "</table>\n";

<input type="submit" name="submit2" value="Select your name and click
here to record your timeout"></form>



-----Original Message-----
From: Eric Schwartz [mailto:eric.j.schwartz@xxxxxxxxx] 
Sent: Friday, 6 August 2004 9:31 AM
To: php-db@xxxxxxxxxxxxx
Subject: Re:  Php if statement in a form


On Fri, 6 Aug 2004 08:53:53 +1000, justin.baiocchi@xxxxxxxx
<justin.baiocchi@xxxxxxxx> wrote:
> Hello, I wonder if someone could point me in the right direction here.
> 
> I have a table that is displayed that is also a form, and allowed a
> person to select a record to update using a radio button. With one of
> the fields of the form/table however, I would like it to display the
> value in the db (if there is one). If there is no value then I want
the
> field to display the current time and then submit it to the db as a
> variable.
> 
> I can get it to display the current time and submit it to the db, but
I
> don't know how to do the IF bit of the form/table.
> 
> Anyway, the code is below.
> Thanks
> 
> <?
> $dbcnx = @mysql_connect( "localhost", "user", "password");
> mysql_select_db("movements");
> $result = mysql_query("SELECT id, name, location, timein, timeout FROM
> workalone WHERE date=CURRENT_DATE()") or die (mysql_error());
> // Display the results of the query in a table
> print "<b>Current Staff Working Alone</b>";
> //below is the table/form with the id, name, location, timein and
> timeout taken from the db
> print "<table border=\"1\" cellpadding=\"3\" cellspacing=\"0\">\n";
> print
> "<tr><td></td><td><b>Name</b></td><td><b>Location</b></td><td><b>Time
> in</b></td><td><b>Time Out</b></td>/tr>";
> while ($row = mysql_fetch_array($result, MYSQL_BOTH))
> {
>     print "<tr><td>";
>     print "<INPUT TYPE='RADIO' NAME='id' VALUE='".$row["id"]."'>";
>     print "</td><td>";
>     print $row["name"];
>     print "</td><td>";
>     print $row["location"];
>     print "</td><td>";
>     print $row["timein"];
>     print "</td><td>";
> //below is the IF thing I am having problems with
>     ?><input name="timeout" type="text" value="if {$timeout=null <?php
> echo date('H:i');?>} else {<?print $row["timeout"];?>"><?
>     print "</td></tr>\n";
> }
> print "</table>\n";
> 
> ?><input type="submit" name="submit2" value="Select your name and
click
> here to record your timeout"></form>   <?
> 
> if ($submit2)
> {
> $dbcnx = @mysql_connect( "localhost", "user", "password");
> mysql_select_db("movements");
> $result = mysql_query("UPDATE workalone SET timeout='$timeout' WHERE
> id='$id'") or die (mysql_error());
> echo "<b>Thank you, your Time Out has been recorded.</b>";
> 
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

You seem to have your php tags not around your if statement and you
are checking to see if $timeout rather than $row["timeout"] has a
value.  I also think the proper way to check for NULL is to say IS
NULL or NOT NULL, not $foo = NULL.  Could be wrong about that one.


<?php
if ($row["timeout"] IS NULL) {
 echo date('H:i');
} else {
print $row["timeout"];
}
?>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux