Re: Php if statement in a form

From: Date: Fri, 06 Aug 2004 02:18:01 +0000
Subject: Re: Php if statement in a form
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-35610@lists.php.net to get a copy of this message
if (is_null($row["timeout"]).....) Justin.Baiocchi@csiro.au wrote:
Still no joy. The parse error actually refers to the -- if ($row["timeout"] IS NULL); --- line. -----Original Message----- From: Eric Schwartz [mailto:eric.j.schwartz@gmail.com] Sent: Friday, 6 August 2004 11:32 AM To: php-db@lists.php.net Subject: Re: [PHP-DB] Php if statement in a form Sorry. Forgot to remove the word echo from that line. On Thu, 5 Aug 2004 21:29:01 -0400, Eric Schwartz <eric.j.schwartz@gmail.com> wrote:
On Fri, 6 Aug 2004 10:21:19 +1000, justin.baiocchi@csiro.au <justin.baiocchi@csiro.au> wrote:
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@gmail.com] Sent: Friday, 6 August 2004 9:31 AM To: php-db@lists.php.net Subject: Re: [PHP-DB] Php if statement in a form On Fri, 6 Aug 2004 08:53:53 +1000, justin.baiocchi@csiro.au <justin.baiocchi@csiro.au> 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
Try adding a quote on the line and escaping the other quotes, like
this:
print "<input name=\"timeout\" type=\"text\" value=\"".echo
date('H:i')."\">";


« previous php.db (#35610) next »