Php if statement in a form

From: Date: Thu, 05 Aug 2004 22:53:53 +0000
Subject: Php if statement in a form
Groups: php.db 
Request: Send a blank email to php-db+get-35600@lists.php.net to get a copy of this message
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>";

« previous php.db (#35600) next »