Jump to content


Photo

adding a variable as a form is submitted


  • Please log in to reply
2 replies to this topic

#1 mattennant

mattennant
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 21 April 2006 - 11:41 AM

hi there

on the homepage of the site i am building the user can subscribe to an email newsletter. It's a simple text box which on submitting adds the email to a database. What i am trying to achieve is th add a thankyou for subscribing to the textbox after the user has submitted there details.

here's the code for the form

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
            <table align="center">
              <tr valign="baseline">
                <td><input type="text" name="email" value="<?php 
         if ($thankyou == "yes") {
        echo "thankyou";
        }else{
         } 
         ?>
" size="23"></td>
              </tr>
              <tr valign="baseline">
                <td><input type="submit" value="submit"></td>
              </tr>
            </table>
            <input type="hidden" name="thankyou" value="thankyou">
            <input type="hidden" name="MM_insert" value="form1">

i now as far as i see it need to add

$thankyou = "yes";


somewhere in the insert record code that dreamweaver has spewed out

<?php require_once('Connections/balance.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$thankyou = "yes";
  $insertSQL = sprintf("INSERT INTO balance_newsletter (email, thankyou) VALUES (%s, %s)",
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['thankyou'], "text"));
                        
  mysql_select_db($database_balance, $balance);
  $Result1 = mysql_query($insertSQL, $balance) or die(mysql_error());
    
  $insertGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
  
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
   
}

but where

i have tried just about everywhere to no avail

any ideas mat

#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 22 April 2006 - 02:04 AM

I don't think they would mind you could probably post this in the main forum, more people look there someone may help, but this is relating to php, I don't think they would mind.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 mattoahu

mattoahu
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 05 May 2006 - 11:23 PM



add this to php just before if ($thankyou=='yes')

$thankyou=$_POST['thankyou'];


change in form
<input type="hidden" name="thankyou" value="thankyou">
to
<input type="hidden" name="thankyou" value="yes">





<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
            <table align="center">
              <tr valign="baseline">
                <td><input type="text" name="email" value="<?php 
         if ($thankyou == "yes") {
        echo "thankyou";
        }else{
         } 
         ?>
" size="23"></td>
              </tr>
              <tr valign="baseline">
                <td><input type="submit" value="submit"></td>
              </tr>
            </table>
            <input type="hidden" name="thankyou" value="thankyou">
            <input type="hidden" name="MM_insert" value="form1">

i now as far as i see it need to add

$thankyou = "yes";
somewhere in the insert record code that dreamweaver has spewed out

<?php require_once('Connections/balance.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$thankyou = "yes";
  $insertSQL = sprintf("INSERT INTO balance_newsletter (email, thankyou) VALUES (%s, %s)",
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['thankyou'], "text"));
                        
  mysql_select_db($database_balance, $balance);
  $Result1 = mysql_query($insertSQL, $balance) or die(mysql_error());
    
  $insertGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
  
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
   
}

but where

i have tried just about everywhere to no avail

any ideas mat
[/quote]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users