Re: [PHP-DB] Php if statement in a form
On Fri, 6 Aug 2004 08:53:53 +1000, [EMAIL PROTECTED] [EMAIL PROTECTED] 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 bCurrent 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 trtd/tdtdbName/b/tdtdbLocation/b/tdtdbTime in/b/tdtdbTime Out/b/td/tr; while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { print trtd; print INPUT TYPE='RADIO' NAME='id' VALUE='.$row[id].'; print /tdtd; print $row[name]; print /tdtd; print $row[location]; print /tdtd; print $row[timein]; print /tdtd; //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 bThank 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
Re: [PHP-DB] Php if statement in a form
On Fri, 6 Aug 2004 10:21:19 +1000, [EMAIL PROTECTED] [EMAIL PROTECTED] 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 bCurrent Staff Working Alone/b; print /td/tr; print /table\n; print table border=\1\ cellpadding=\3\ cellspacing=\0\\n; print trtd/tdtdbName/b/tdtdbLocation/b/tdtdbTime in/b/tdtdbTime Out/b/td/tr; while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { print trtd; print INPUT TYPE='RADIO' NAME='id' VALUE='.$row[id].'; print /tdtd; print $row[name]; print /tdtd; print $row[location]; print /tdtd; print $row[timein]; print /tdtd; 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:[EMAIL PROTECTED] Sent: Friday, 6 August 2004 9:31 AM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Php if statement in a form On Fri, 6 Aug 2004 08:53:53 +1000, [EMAIL PROTECTED] [EMAIL PROTECTED] 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 bCurrent 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 trtd/tdtdbName/b/tdtdbLocation/b/tdtdbTime in/b/tdtdbTime Out/b/td/tr; while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { print trtd; print INPUT TYPE='RADIO' NAME='id' VALUE='.$row[id].'; print /tdtd; print $row[name]; print /tdtd; print $row[location]; print /tdtd; print $row[timein]; print /tdtd; //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 bThank 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').\; -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
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 [EMAIL PROTECTED] wrote: On Fri, 6 Aug 2004 10:21:19 +1000, [EMAIL PROTECTED] [EMAIL PROTECTED] 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 bCurrent Staff Working Alone/b; print /td/tr; print /table\n; print table border=\1\ cellpadding=\3\ cellspacing=\0\\n; print trtd/tdtdbName/b/tdtdbLocation/b/tdtdbTime in/b/tdtdbTime Out/b/td/tr; while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { print trtd; print INPUT TYPE='RADIO' NAME='id' VALUE='.$row[id].'; print /tdtd; print $row[name]; print /tdtd; print $row[location]; print /tdtd; print $row[timein]; print /tdtd; 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:[EMAIL PROTECTED] Sent: Friday, 6 August 2004 9:31 AM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Php if statement in a form On Fri, 6 Aug 2004 08:53:53 +1000, [EMAIL PROTECTED] [EMAIL PROTECTED] 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 bCurrent 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 trtd/tdtdbName/b/tdtdbLocation/b/tdtdbTime in/b/tdtdbTime Out/b/td/tr; while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { print trtd; print INPUT TYPE='RADIO' NAME='id' VALUE='.$row[id].'; print /tdtd; print $row[name]; print /tdtd; print $row[location]; print /tdtd; print $row[timein]; print /tdtd; //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 bThank 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').\; -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php