html - Disabling submit button permanently if desired value is inserted into database - php -
the next update form updates info nutrient preference of each user in password protected area under predefined answers of questionnaire.
for example,
question: what's favorite food?
answer:
cheese meat saladthe submit button of next form should disabled permanently based on predefined value of variable $trigger
when user submit it.
$trigger = '1'; if ((isset($_post["mm_update"])) && ($_post["mm_update"] == "formx")) { $updatesql = sprintf("update foodtable set food_preference=%s, trigger=%s, food_id=%s", getsqlvaluestring($_post['food_preference'], "text"), getsqlvaluestring(trim($trigger), "int"), getsqlvaluestring($_post['food_id'], "int")); mysql_select_db($database_xyz, $xyz); $result1 = mysql_query($updatesql, $xyz) or die(mysql_error()); $updategoto = "preference.php"; if (isset($_server['query_string'])) { $updategoto .= (strpos($updategoto, '?')) ? "&" : "?"; $updategoto .= $_server['query_string']; } header(sprintf("location: %s", $updategoto)); exit (); }
<form action="<?php echo $editformaction; ?>" method="post" name="formx" id="formx"> <table align="center"> <tr valign="baseline"> <td align="right" nowrap="nowrap">update nutrient name:</td> <td><input type="text" name="food_name" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> <input type="hidden" name="mm_update" value="formx" /> <input type="hidden" name="trigger" value="<?php echo "$trigger"; ?>" /> </td> <td> <input type="submit" value="update nutrient name" /> </td> </tr> </table> </form>
how perform pure php conditional statement? should bring alter in html form code too? reference or suggestion shall appreciated.
edit
the next update form updates nutrient preference of individual user in password protected user area.
$trigger = '1'; //note: default value of $trigger= '0'; when user submits info using insert form primarily. when update info using update form value changes `1` if ((isset($_post["mm_update"])) && ($_post["mm_update"] == "formx")) { $updatesql = sprintf("update foodtable set food_name=%s, trigger=%s food_id=%s", getsqlvaluestring($_post['food_name'], "text"), getsqlvaluestring(trim($trigger), "int"), getsqlvaluestring($_post['food_id'], "int")); mysql_select_db($database_xyz, $xyz); $result1 = mysql_query($updatesql, $xyz) or die(mysql_error()); $updategoto = "preference.php"; if (isset($_server['query_string'])) { $updategoto .= (strpos($updategoto, '?')) ? "&" : "?"; $updategoto .= $_server['query_string']; } header(sprintf("location: %s", $updategoto)); exit (); }
<form action="<?php echo $editformaction; ?>" method="post" name="formx" id="formx"> <table align="center"> <tr valign="baseline"> <td align="right" nowrap="nowrap">update nutrient name:</td> <td><input type="text" name="food_name" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> <input type="hidden" name="mm_update" value="formx" /> <input type="hidden" name="food_id" value="<?php echo $query['food_id']; ?>" /> <input type="hidden" name="trigger" value="<?php echo "$trigger"; ?>" /> </td> <td> < ?php $disabled = "disabled"; if (isset (which conditional statement shall disable form permanently based on $trigger = '1'; ?)) { echo "<input type='submit' value='update nutrient name' " . $disabled . "/>"; }else{ echo "<input type='submit' value='update nutrient name'/>"; } ?> </td> </tr> </table> </form>
by way, utilize next mysql syntax column values disabling submit button:
$query = "select food_id, food_name, trigger foodtable food_id > 0 , trigger = '1'";
whhich conditional php statement should utilize disable form indicated html portion of edited post?
it can solved in lengthy way, expecting reasonable method.
if sense question makes clear enough, reply shall appreciated.
i next way. 1 time user submits form flag written session (however recommend storing info in database, since session reset if closes , re-opens browser; code should help started).
first of all, @ start of script initialize session:
session_start();
then, before update check if has not submitted info already:
if ((!isset($_session['has_submitted']) or !$_session['has_submitted']) , (isset($_post["mm_update"])) , ($_post["mm_update"] == "formx")) {
and, of course, need set flag after update:
$result1 = mysql_query($updatesql, $xyz) or die(mysql_error()); $_session['has_submitted'] = true;
finally, when echo submit button, check flag , deed accordingly:
<input type="submit" value="update nutrient name" <?php echo ((isset($_session['has_submitted']) , $_session['has_submitted']) ? 'disabled' : ''); ?> />
edit
when user enters page, need current trigger
value:
$trigger = mysql_query("select trigger foodtable food_id=...");
then check $trigger
variable when form output or submitted (assuming user has somehow enabled form):
if (!$trigger , (isset($_post["mm_update"])) , ($_post["mm_update"] == "formx"))
and
<input type="submit" value="update nutrient name" <?php echo ($trigger ? 'disabled' : ''); ?> />
php html mysql forms
No comments:
Post a Comment