How can I make this code submit itself when the page loads..

  • Mozzi
  • Student
  • Student
  • Mozzi
  • Posts: 70

Post 3+ Months Ago

Hi.. I have this update page.. but i have a form in it .. i want to form to autosubmit on load

or even better the recode it so to update without having to submit...

Is there a way to recode this???

I have tried to remove the if (isset($_POST['button']))so it automaticly updates.. but i have no luck as it seems like this needs to be pressed to do the function.. im a bit of a newbie to HARD CODE HAND CODING.. so if anyone could assist then it would be great

Code: [ Select ]
<?php require_once('../Connections/customer_zone.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
 $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 switch ($theType) {
  case "text":
   $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
   break;
  case "long":
  case "int":
   $theValue = ($theValue != "") ? intval($theValue) : "NULL";
   break;
  case "double":
   $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
   break;
  case "date":
   $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
   break;
  case "defined":
   $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
   break;
 }
 return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
 $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

mysql_select_db($database_customer_zone, $customer_zone);
$query_Recordset1 = "SELECT * FROM claims";
$Recordset1 = mysql_query($query_Recordset1, $customer_zone) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

// *** FX Update Multiple Records in form1
if (isset($startRow_Recordset1)) $upd_Recordset1 = $startRow_Recordset1; else $upd_Recordset1 = 0; // counter
if (isset($_POST['button'])) {
 $FX_sqlerror = "";
 $FX_updredir = "view_claim.php";
 mysql_select_db($database_customer_zone, $customer_zone);
 for ($N=$upd_Recordset1+1; $N<=$totalRows_Recordset1; $N++) {
  $updt_SQL = sprintf("UPDATE claims SET policy_gi_ref=%s, `read`=%s WHERE policy_gi_ref=%s",
            isset($_POST["policy_gi_ref$N"]) ? ($_POST["policy_gi_ref$N"] != "" ? ("'".addslashes(stripslashes($_POST["policy_gi_ref$N"]))."'") : "NULL") : "''",
            isset($_POST["read$N"]) ? ($_POST["read$N"] != "" ? ("'".addslashes(stripslashes($_POST["read$N"]))."'") : "NULL") : "''",
            isset($_POST["fx_updmatch$N"]) ? ($_POST["fx_updmatch$N"] != "" ? ("'".addslashes(stripslashes($_POST["fx_updmatch$N"]))."'") : "NULL") : "''");
  $updt_Result = mysql_query($updt_SQL, $customer_zone) or $FX_sqlerror .= "Row ".$N.": " . mysql_error() . "<br><br>";
 }
 if ($FX_updredir == "") $FX_updredir = basename($_SERVER['SCRIPT_NAME']);
 if (isset($_SERVER['QUERY_STRING'])) {
  $FX_updredir .= (strpos($FX_updredir, '?')) ? "&" : "?";
  $FX_updredir .= $_SERVER['QUERY_STRING'];
 }
 if ($FX_sqlerror != "") {
  echo '<font color="red">'.$FX_sqlerror.'</font>';
 } else header("Location: " . $FX_updredir);
}
?>

<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
 <?php do { ?>

     <?php $upd_Recordset1++; ?>
     <input type="hidden" name="fx_updmatch<?php echo $upd_Recordset1; ?>" value="<?php echo $row_Recordset1['policy_gi_ref']; ?>" />
     <input name="policy_gi_ref<?php echo $upd_Recordset1; ?>" type="hidden" id="policy_gi_ref" value="<?php echo $row_Recordset1['policy_gi_ref']; ?>" />
    <input name="read<?php echo $upd_Recordset1; ?>" type="hidden" id="read" value="no" />

  <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>


  <input type="submit" name="button" id="button" value="Submit" />

</form>

<?php
mysql_free_result($Recordset1);
?>
  1. <?php require_once('../Connections/customer_zone.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  7.  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  8.  switch ($theType) {
  9.   case "text":
  10.    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  11.    break;
  12.   case "long":
  13.   case "int":
  14.    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  15.    break;
  16.   case "double":
  17.    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  18.    break;
  19.   case "date":
  20.    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  21.    break;
  22.   case "defined":
  23.    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  24.    break;
  25.  }
  26.  return $theValue;
  27. }
  28. }
  29. $editFormAction = $_SERVER['PHP_SELF'];
  30. if (isset($_SERVER['QUERY_STRING'])) {
  31.  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  32. }
  33. mysql_select_db($database_customer_zone, $customer_zone);
  34. $query_Recordset1 = "SELECT * FROM claims";
  35. $Recordset1 = mysql_query($query_Recordset1, $customer_zone) or die(mysql_error());
  36. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  37. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  38. // *** FX Update Multiple Records in form1
  39. if (isset($startRow_Recordset1)) $upd_Recordset1 = $startRow_Recordset1; else $upd_Recordset1 = 0; // counter
  40. if (isset($_POST['button'])) {
  41.  $FX_sqlerror = "";
  42.  $FX_updredir = "view_claim.php";
  43.  mysql_select_db($database_customer_zone, $customer_zone);
  44.  for ($N=$upd_Recordset1+1; $N<=$totalRows_Recordset1; $N++) {
  45.   $updt_SQL = sprintf("UPDATE claims SET policy_gi_ref=%s, `read`=%s WHERE policy_gi_ref=%s",
  46.             isset($_POST["policy_gi_ref$N"]) ? ($_POST["policy_gi_ref$N"] != "" ? ("'".addslashes(stripslashes($_POST["policy_gi_ref$N"]))."'") : "NULL") : "''",
  47.             isset($_POST["read$N"]) ? ($_POST["read$N"] != "" ? ("'".addslashes(stripslashes($_POST["read$N"]))."'") : "NULL") : "''",
  48.             isset($_POST["fx_updmatch$N"]) ? ($_POST["fx_updmatch$N"] != "" ? ("'".addslashes(stripslashes($_POST["fx_updmatch$N"]))."'") : "NULL") : "''");
  49.   $updt_Result = mysql_query($updt_SQL, $customer_zone) or $FX_sqlerror .= "Row ".$N.": " . mysql_error() . "<br><br>";
  50.  }
  51.  if ($FX_updredir == "") $FX_updredir = basename($_SERVER['SCRIPT_NAME']);
  52.  if (isset($_SERVER['QUERY_STRING'])) {
  53.   $FX_updredir .= (strpos($FX_updredir, '?')) ? "&" : "?";
  54.   $FX_updredir .= $_SERVER['QUERY_STRING'];
  55.  }
  56.  if ($FX_sqlerror != "") {
  57.   echo '<font color="red">'.$FX_sqlerror.'</font>';
  58.  } else header("Location: " . $FX_updredir);
  59. }
  60. ?>
  61. <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  62.  <?php do { ?>
  63.      <?php $upd_Recordset1++; ?>
  64.      <input type="hidden" name="fx_updmatch<?php echo $upd_Recordset1; ?>" value="<?php echo $row_Recordset1['policy_gi_ref']; ?>" />
  65.      <input name="policy_gi_ref<?php echo $upd_Recordset1; ?>" type="hidden" id="policy_gi_ref" value="<?php echo $row_Recordset1['policy_gi_ref']; ?>" />
  66.     <input name="read<?php echo $upd_Recordset1; ?>" type="hidden" id="read" value="no" />
  67.   <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  68.   <input type="submit" name="button" id="button" value="Submit" />
  69. </form>
  70. <?php
  71. mysql_free_result($Recordset1);
  72. ?>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • nexuslite
  • Newbie
  • Newbie
  • nexuslite
  • Posts: 10
  • Loc: Keizer, OR

Post 3+ Months Ago

I usually use

Code: [ Select ]
if (isset($_POST) && count($_POST)) {
}
  1. if (isset($_POST) && count($_POST)) {
  2. }


rather than

Code: [ Select ]
if (isset($_POST['button'])) {
}
  1. if (isset($_POST['button'])) {
  2. }



this way it is only checking if the post variable has content. then a JavaScript form submit will need to be added to it to make it auto submit the form.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 137 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.