Missing data

Hello all,

I have a userUpdate page which allows users to update their details. It was working fine but for some reason it no longer inserts the required data.

The form should populate the form by session variable MM_User_ID, but it's not happening.

Please have a look at the code and tell me what's gone wrong.

Many thanks,

Tim
<?php session_start(); ?>
<?php require_once('Connections/connpbw.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"] == "userUpdateRecord")) {
  $updateSQL = sprintf("UPDATE users SET email=%s, pwd=%s, first_name=%s, last_name=%s, country=%s, telephone=%s, wineExperience=%s, news=%s, offers=%s, advice=%s WHERE user_id=%s",
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['pwd'], "text"),
                       GetSQLValueString($_POST['first_name'], "text"),
                       GetSQLValueString($_POST['last_name'], "text"),
                       GetSQLValueString($_POST['country'], "text"),
                       GetSQLValueString($_POST['telephone'], "text"),
                       GetSQLValueString($_POST['wineExperience'], "text"),
                       GetSQLValueString($_POST['news'], "text"),
                       GetSQLValueString($_POST['offers'], "text"),
                       GetSQLValueString($_POST['advice'], "text"),
                       GetSQLValueString($_POST['user_id'], "int"));
 
  mysql_select_db($database_connpbw, $connpbw);
  $Result1 = mysql_query($updateSQL, $connpbw) or die(mysql_error());
 
  $updateGoTo = "userupdate.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}
 
$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_User_ID'])) {
  $colname_Recordset1 = $_SESSION['MM_User_ID'];
}
mysql_select_db($database_connpbw, $connpbw);
$query_Recordset1 = sprintf("SELECT * FROM users WHERE user_id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $connpbw) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PBW SITE</title>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script type="text/javascript">
function mypopup(video)
 {
     mywindow = window.open("player.html?v=" + video, "mywindow", "toolbar=no,location=no,status=no,scrollbars=no, width=425,height=344");
 
 }
</script>
<script src="Scripts/AC_ActiveX.js" type="text/javascript"></script>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<link href="pbw site.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
	margin-top: 0px;
}
 
-->
</style>
<!-- TemplateParam name="width" type="text" value="475" -->
</head>
 
<body>
 
<div id="wrap">
<script type="text/javascript">
 
</script>
<?php include("includes/header.php"); ?>
<form action="<?php echo $editFormAction; ?>" method="POST" name="userUpdateRecord" class="form_background" id="userUpdateRecord">
  <table width="982" border="0" class="form_background">
    <tr>
      <td bgcolor="#CCCCCC" class="form_background">&nbsp;</td>
    </tr>
  </table>
  <table align="center" class="form_format">
    <tr valign="baseline">
      <td height="25" colspan="2" align="center"  fontsize="18" nowrap="nowrap" class="form_Title">  User Account Updater </td>
      </tr>
    <tr valign="baseline">
      <td width="250" height="25" align="right" nowrap="nowrap">User ID:</td>
      <td width="250"><?php echo $row_Recordset1['user_id']; ?></td>
    </tr>
    <tr valign="baseline">
      <td width="250" height="25" align="right" nowrap="nowrap" id="formUserUpdate">Date Registered:</td>
<td width="250" ><?php echo $row_Recordset1['date_registered']; ?></td>
    </tr>
    <tr valign="baseline">
      <td width="250" height="25" align="right" nowrap="nowrap">Email:</td>
      <td width="250"><span id="sprytextfield1">
      <input name="email" type="text" class="content" value="<?php echo $row_Recordset1['email']; ?>" size="32" />
      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td width="250" height="25" align="right" nowrap="nowrap">First Name:</td>
      <td width="250"><span id="sprytextfield2">
        <input name="first_name" type="text" value="<?php echo $row_Recordset1['first_name']; ?>" size="32" />
        <span class="textfieldRequiredMsg">A value is required.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td width="250" height="25" align="right" nowrap="nowrap">Last Name:</td>
      <td width="250"><span id="sprytextfield3">
        <input name="last_name" type="text" value="<?php echo $row_Recordset1['last_name']; ?>" size="32" />
        <span class="textfieldRequiredMsg">A value is required.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td width="250" height="25" align="right" nowrap="nowrap">Country:</td>
      <td width="250"><span id="sprytextfield4">
        <input name="country" type="text" value="<?php echo $row_Recordset1['country']; ?>" size="32" />
        <span class="textfieldRequiredMsg">A value is required.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td width="250" height="25" align="right" nowrap="nowrap">Telephone:</td>
      <td width="250"><span id="sprytextfield5">
        <input name="telephone" type="text" value="<?php echo $row_Recordset1['telephone']; ?>" size="32" />
        <span class="textfieldRequiredMsg">A value is required.</span></span></td>
    </tr>
    <tr valign="baseline">
      <td width="250" align="right" nowrap="nowrap">&nbsp;</td>
      <td width="250" valign="baseline"><input name="wineExperience" type="hidden" id="wineExperience" value="<?php echo $row_Recordset1['wineExperience']; ?>" />
        <input name="news" type="hidden" id="news" value="<?php echo $row_Recordset1['news']; ?>" />
        <input name="offers" type="hidden" id="offers" value="<?php echo $row_Recordset1['offers']; ?>" />
        <input name="advice" type="hidden" id="advice" value="<?php echo $row_Recordset1['advice']; ?>" />
        <input name="hiddenField2" type="hidden" id="hiddenField2" /> <input name="hiddenField" type="hidden" id="hiddenField" value="<?php echo $row_Recordset1['pwd']; ?>" /></td>
    </tr>
    <tr valign="baseline">
<td width="250" align="right" nowrap="nowrap">&nbsp;</td>
      <td width="250">&nbsp;</td>
    </tr>
    <tr valign="baseline">
      <td width="250" align="right" nowrap="nowrap">&nbsp;</td>
      <td width="250"><input name="update" type="submit" id="update" value="Update record" /></td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <p>
    <input type="hidden" name="user_id" value="<?php echo $row_Recordset1['user_id']; ?>" />
  </p>
  <input type="hidden" name="MM_update" value="userUpdateRecord" />
</form>
<?php include("includes/footer.php"); ?>
<p>&nbsp;</p>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "email", {clone:(function () {var o = new Object();for (var property in this) {o[property] = typeof (this[property]) == "object" ? this[property].clone() : this[property];}return o;}), validateOn:["blur"]});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "none", {validateOn:["blur"], clone:(function () {var o = new Object();for (var property in this) {o[property] = typeof (this[property]) == "object" ? this[property].clone() : this[property];}return o;})});
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "none", {validateOn:["blur"], clone:(function () {var o = new Object();for (var property in this) {o[property] = typeof (this[property]) == "object" ? this[property].clone() : this[property];}return o;})});
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "none", {validateOn:["blur"], clone:(function () {var o = new Object();for (var property in this) {o[property] = typeof (this[property]) == "object" ? this[property].clone() : this[property];}return o;})});
var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5", "none", {validateOn:["blur"], clone:(function () {var o = new Object();for (var property in this) {o[property] = typeof (this[property]) == "object" ? this[property].clone() : this[property];}return o;})});
//-->
</script>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Open in new window

TimDuntonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason C. LevineNo oneCommented:
Navigate to the page and then view-source to make sure this line is being populated:

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

The user_id is required for the Update Behavior to fire.  If it is not set, then you have a problem with the page that leads to this page.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Neil_BradleyWeb UX/UI DeveloperCommented:
Have you applied the Server Behavior to restrict access to the page? If you have not the session variable MM_User_ID wont do its job. The second you apply this, the session variable will pick up on the session info.
0
Jason C. LevineNo oneCommented:
The code above has session_start() in it so if the user us logged in, the variable is now available...
0
TimDuntonAuthor Commented:
Sorry guys, thanks for the feedback, I have been away and so have not had a chance to check out your suggestions. It's nearly midnight here now (I'm in the UK) so I'll have a play around tomorrow. Thanks again, hope you both had a good weekend.
0
TimDuntonAuthor Commented:
Unfortunately I couldn't identify the problem so I created a new form  and populated by username rather than ID. That seemed to work but I'm still not sure why the MM_User_ID session variable would not.

Thanks anyway guys for your assistance, much appreciated.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Dreamweaver

From novice to tech pro — start learning today.