Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

update a record is updating the first record in the DB...HELP!

Engaged ,
Jun 13, 2012 Jun 13, 2012

Copy link to clipboard

Copied

I am going over and over this again and cant find the problem.

i have a form that sends email to emails that are on a php mysql db however when i update certain records it always is updating the first record in the DB...i have looked over this so many times and cant see what is going wrong

the userid is not auto_increment but is based on the username (these are all unique)

i have uncluded the code to see if i am missing something

<?php require_once('../Connections/hostprop.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  if (PHP_VERSION < 6) {

    $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']);

}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {

  $updateSQL = sprintf("UPDATE plus_signup SET email=%s, emailerSubject=%s, emailerContent=%s WHERE userid=%s",

                       GetSQLValueString($_POST['email'], "text"),

                       GetSQLValueString($_POST['emailerSubject'], "text"),

                       GetSQLValueString($_POST['emailerContent'], "text"),

                       GetSQLValueString($_POST['userid'], "text"));

  mysql_select_db($database_hostprop, $hostprop);

  $Result1 = mysql_query($updateSQL, $hostprop) or die(mysql_error());

 

      // Email Guarantor

          $to = $_POST['email'];

          $subject = "Email From Host Student Property";

          $message = "

          <html>

                    <head>

                              <title>Dear ".GetSQLValueString($_POST['userid'], "text")."</title>

                    </head>

                    <body>

                              <img src=\"http://www.hoststudent.co.uk/beta/images/hostlogo.gif\" alt=\"www.HostStudent.co.uk\" />

                              <h2>An Email From Host Students</h2>

                              <br /><br />

                              <table>

                                        <tr>

                                                  <td>Email Subject:</td>

                                        </tr>

                                        <tr>

                                                  <td>".GetSQLValueString($_POST['emailerSubject'], "text")."</td>

                                        </tr>

                                        <tr>

                                                  <td>Email Content</td>

                                        </tr>

                                        <tr>

                                                  <td>".GetSQLValueString($_POST['emailerContent'], "text")."</td>

                                        </tr>

                              </table>

                    </body>

          </html>

          ";

 

          // Always set content-type when sending HTML email

          $headers = "MIME-Version: 1.0" . "\r\n";

          $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

          $headers .= 'From: HostStudent.co.uk <noreply@hoststudent.co.uk>' . "\r\n";

 

          $send = mail($to,$subject,$message,$headers);

  $updateGoTo = "TenantEmailSent.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";

    $updateGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $updateGoTo));

}

mysql_select_db($database_hostprop, $hostprop);

$query_Recordset1 = "SELECT userid, email, emailerSubject, emailerContent FROM plus_signup";

$Recordset1 = mysql_query($query_Recordset1, $hostprop) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>

<?

          session_start();

          if(!$_SESSION['loggedIn']) // If the user IS NOT logged in, forward them back to the login page

          {

                    header("location:Login.html");

          }

?>

   <script type="text/javascript">

function loadFields(Value) {

         var Guarantor = Value.split("|");

          var userid1 = Guarantor[0] ;

                      var GuName = Guarantor[1];

          var GuPhoneEmail = Guarantor[2] ;

                     

          document.getElementById('userid1').value=userid1;

                      document.getElementById('GuName').value=GuName;

          document.getElementById('GuPhoneEmail').value=GuPhoneEmail;

}

</script>

<form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">

              <table align="center">

      <tr valign="baseline">

        <td nowrap="nowrap" align="right"> </td>

        <td><select name="userid" id="userid" onchange="loadFields(this.value)">

          <option value="Select Guarantor">Select Guarantor</option>

          <?php

do {

?>

         

<option value="<?php echo $row_Recordset1['userid'] . '|' . $row_Recordset1['GuName'] . '|' . $row_Recordset1['GuPhoneEmail'];?>"><?php echo $row_Recordset1['userid'] . " , " . $row_Recordset1['GuName'] . " , " . $row_Recordset1['GuPhoneEmail']; ?></option>

          <?php

} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));

  $rows = mysql_num_rows($Recordset1);

  if($rows > 0) {

      mysql_data_seek($Recordset1, 0);

            $row_Recordset1 = mysql_fetch_assoc($Recordset1);

  }

?>

        </select></td>

      </tr>

      <tr valign="baseline">

        <td nowrap="nowrap" align="right">Tenant Name</td>

        <td><input type="text" name="userid1" id="userid1" readonly="readonly" value="<?php echo htmlentities($row_Recordset1['userid'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>

      </tr>

      <tr valign="baseline">

        <td nowrap="nowrap" align="right">GuName:</td>

        <td><input type="text" name="GuName" id="GuName" readonly="readonly" value="<?php echo htmlentities($row_Recordset1['GuName'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>

      </tr>

      <tr valign="baseline">

        <td nowrap="nowrap" align="right">GuPhoneEmail:</td>

        <td><input type="text" name="GuPhoneEmail" id="GuPhoneEmail" readonly="readonly" value="<?php echo htmlentities($row_Recordset1['GuPhoneEmail'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>

      </tr>

      <tr valign="baseline">

        <td nowrap="nowrap" align="right">GuEmailerSubject:</td>

        <td><input type="text" name="GuEmailerSubject" value="" size="32" /></td>

      </tr>

      <tr valign="baseline">

        <td nowrap="nowrap" align="right">GuEmailerContent:</td>

        <td><textarea name="GuEmailerContent" cols="45" rows="5"> </textarea></td>

      </tr>

      <tr valign="baseline">

        <td nowrap="nowrap" align="right"> </td>

        <td><input type="submit" value="Send email" /></td>

      </tr>

      <tr valign="baseline">

        <td nowrap="nowrap" align="right"></td>

        <td> </td>

      </tr>

              </table>

    <input type="hidden" name="MM_update" value="form2" />

    <input type="hidden" name="userid" value="<?php echo $row_Recordset1['userid']; ?>" />

</form>

TOPICS
Server side applications

Views

513
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Jun 13, 2012 Jun 13, 2012

i have found the problem, there were two forms with the same name..

thanks

Votes

Translate
Engaged ,
Jun 13, 2012 Jun 13, 2012

Copy link to clipboard

Copied

LATEST

i have found the problem, there were two forms with the same name..

thanks

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines