Jump to content

[SOLVED] Updating the wrong fields in database!


Anxious

Recommended Posts

I have alot of problems,

I have 5 tables, but we only need to focus on 2

Table PROFILE, and table USERS.

 

USERS has the register details, and PROFILE has the profile details.

Okay, here are the problems.

 

Table PROFILE

The value entered in the fullname field on the edit profile page, ends up on the slogan field in this table.

SchoolJob, Dislikes, Music, Status and Slogan don't get entered at all.

 

Table USERS

Status value ends up in the gender field in this table.

School or Job ends up in the location field in this table.

 

Slogan, FullName, profilelocation, schooljob, status, likes, dislikes, music should all be in database Table PROFILE. Shouldn't be touched with table USERS

 

Think I covered it.. I'll send the codes in the next post.

Link to comment
Share on other sites

Edit Profile Page

<?php <form action="process.php" method="POST">
    <table width="708" border="0" align="center" cellpadding="3" cellspacing="0">
      <tr>
        <td width="151">Profile Header:</td>
        <td width="377"><input name="slogan" type="text" value="
<? if($form->value("slogan") == ""){
   echo $database->getUserProfileInfo['slogan'];
}else{
   echo $form->value("slogan");
} ?>" size="60" maxlength="100"></td>
      </tr>
  <tr>
  <td><br>
  Full Name:</td>
  <Td><p> <br>
  <input name="fullname" type="text" value="<? if($form->value("fullname") == ""){
  echo $database->getUserProfileInfo['fullname'];
  }else{
  echo $form->value("fullname");
  } ?>" size="60" maxlength="100">
      <tr>
        <td><br>
          Location:</td>
        <td><p> <br>
                <input name="profilelocation" type="text" value="<? if($form->value("profilelocation") == ""){
   echo$database->getUserProfileInfo['profilelocation'];
}else{
   echo $form->value("profilelocation");
} ?>" size="60" maxlength="100">
        </td>
      </tr>
      <tr>
        <td><br>
          School/Job</td>
        <td><p> <br>
                <input name="schooljob" type="text" value="
<? if($form->value("schooljob") == ""){
   echo $database->getUserProfileInfo['schooljob'];
}else{
   echo $form->value("schooljob");
} ?>" size="60" maxlength="100">
        </td>
      </tr>
      <tr>
        <td><br>
          Martial Status</td>
        <td><p> <br>
                <select name="status" value="<? if($form->value("status") == ""){
echo $database->getUserProfileInfo['status'];
}else{
echo $form->value("status");
} ?>">
                  <option value="Not Specified" selected>Not Specified</option>
                  <option value="Single">Single</option>
                  <option value="Dating">Dating</option>
                  <option value="In A Relationship">In A Relationship</option>
                  <option value="Engaged">Engaged</option>
                  <option value="Marriage">Marriage</option>
                  <option value="Swinger">Swinger</option>
                  <option value="It's Complicated">It's Complicated</option>
                </select>
        </td>
      </tr>
      <tr>
        <td><br>
          Likes:</td>
        <td><p> <br>
                <textarea name="likes" cols="60" rows="10" value"
<? if($form->value("likes") == ""){
   echo $database->getUserProfileInfo['likes'];
}else{
   echo $form->value("likes");
} ?>">
              </textarea>
        </p></td>
      </tr>
      <tr>
        <td><br>
          Dislikes:</td>
        <td><br>
            <textarea name"dislikes" cols="60" rows="10" value"
<? if($form->value("dislikes") == ""){
   echo $database->getUserProfileInfo['dislikes'];
}else{
   echo $form->value("dislikes");
} ?>"></textarea>
      </tr>
      <tr>
        <td><br>
          Music:</td>
        <td><br>
            <textarea name"music" cols="60" rows="10" value"
<? if($form->value("music") == ""){
   echo $database->getUserProfileInfo['music'];
}else{
   echo $form->value("music");
} ?>"></textarea>
      </tr>
      <tr>
        <td> </td>
        <td><br>
        
        <td><br></td>
      <tr>
        <td colspan="2" align="right"><input type="hidden" name="subeditprofile" value="1">
            <input name="submit" type="submit" value="Submit Changes"></td>
      </tr>
      <tr>
        <td colspan="2" align="left"></td>
      </tr>
    </table>
</form> ?>

 

process.php

<?php    function procEditProfile(){
      global $session, $form;
      /* Account edit attempt */
      $retval = $session->editAccount($_POST['slogan'], $_POST['fullname'], $_POST['profilelocation'], $_POST['schooljob'], $_POST['status'],  $_POST['likes'], $_POST['dislikes'], $_POST['music']);

      /* Account edit successful */
      if($retval){
         $_SESSION['useredit'] = true;
         header("Location: ".$session->referrer);
      }
      /* Error found with form */
      else{
         $_SESSION['value_array'] = $_POST;
         $_SESSION['error_array'] = $form->getErrorArray();
         header("Location: ".$session->referrer);
      }
   }

   function procEditAccount(){
      global $session, $form;
      /* Account edit attempt */
      $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['location'], $_POST['gender']);

      /* Account edit successful */
      if($retval){
         $_SESSION['useredit'] = true;
         header("Location: ".$session->referrer);
      }
      /* Error found with form */
      else{
         $_SESSION['value_array'] = $_POST;
         $_SESSION['error_array'] = $form->getErrorArray();
         header("Location: ".$session->referrer);
      }
   } ?>

 

Session.php

<?php    function editAccount($subcurpass, $subnewpass, $subemail, $sublocation, $subgender, $subslogan, $subprofilelocation, $schooljob, $status, $sublikes, $subdislikes, $submusic){
      global $database, $form;  //The database and form object
        /* New password entered */
      if($subnewpass){
         /* Current Password error checking */
         $field = "curpass";  //Use field name for current password
         if(!$subcurpass){
            $form->setError($field, "* Current Password not entered");
         }
         else{
            /* Check if password too short or is not alphanumeric */
            $subcurpass = stripslashes($subcurpass);
            if(strlen($subcurpass) < 4 ||
               !eregi("^([0-9a-z])+$", ($subcurpass = trim($subcurpass)))){
               $form->setError($field, "* Current Password incorrect");
            }
            /* Password entered is incorrect */
            if($database->confirmUserPass($this->username,md5($subcurpass)) != 0){
               $form->setError($field, "* Current Password incorrect");
            }
         }
         
         /* New Password error checking */
         $field = "newpass";  //Use field name for new password
         /* Spruce up password and check length*/
         $subpass = stripslashes($subnewpass);
         if(strlen($subnewpass) < 4){
            $form->setError($field, "* New Password too short");
         }
         /* Check if password is not alphanumeric */
         else if(!eregi("^([0-9a-z])+$", ($subnewpass = trim($subnewpass)))){
            $form->setError($field, "* New Password not alphanumeric");
         }
      }
      /* Change password attempted */
      else if($subcurpass){
         /* New Password error reporting */
         $field = "newpass";  //Use field name for new password
         $form->setError($field, "* New Password not entered");
      }
      
      /* Email error checking */
      $field = "email";  //Use field name for email
      if($subemail && strlen($subemail = trim($subemail)) > 0){
         /* Check if valid email address */
         $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
                 ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
                 ."\.([a-z]{2,}){1}$";
         if(!eregi($regex,$subemail)){
            $form->setError($field, "* Email invalid");
         }
         $subemail = stripslashes($subemail);
      }
  
           $field = "location";  //Use field name for current password
         if(!$sublocation){
            $form->setError($field, "* Location not entered");
         }

	          $field = "gender";  //Use field name for current password
         if(!$subgender){
            $form->setError($field, "* Gender not entered");
         }
  
  /* Change Slogan */
  if($subslogan){
  $database->updateUserProfile($this->username,"slogan",$subslogan);
  }
  
  if($subfullname){
  $database->updateUserProfile($this->username,"fullname",$subfullname);
  }
  
  if($subprofilelocation){
  $database->updateUserProfile($this->username,"profilelocation",$subprofilelocation);
  }
  
  if($subschooljob){
  $database->updateUserProfile($this->username,"schooljob",$subschooljob);
  }
  
  if($substatus){
  $database->updateUserProfile($this->username,"status",$substatus);
  }
  
  	  /* Change Likes */
  if($sublikes){
  $database->updateUserProfile($this->username,"likes",$sublikes);
  }
  
  /* Change Dislikes */
  if($subdislikes){
  $database->updateUserProfile($this->username,"dislikes",$subdislikes);
  }
  
  /* Change Music */
  if($submusic){
  $database->updateUserProfile($this->username,"music",$submusic);
  }
  
        /* Update password since there were no errors */
      if($subcurpass && $subnewpass){
         $database->updateUserField($this->username,"password",md5($subnewpass));
      }
  
  if($subcurpass && subnewpass){
  $database->updateUserProfile($this->username,"password",md5($subnewpass));
  }
      
      /* Change Email */
      if($subemail){
         $database->updateUserField($this->username,"email",$subemail);
      }
  
  if($sublocation){
  $database->updateUserField($this->username,"location",$sublocation);
  }
  
  if($subgender){
  $database->updateUserField($this->username,"gender",$subgender);
  }
       
      /* Success! */
      return true;
   } ?>

 

database.php

<?php    function updateUserField($username, $field, $value){
      $q = "UPDATE ".TBL_USERS." SET ".$field." = '$value' WHERE username = '$username'";
      return mysql_query($q, $this->connection);
   }
   
   function updateUserProfile($username, $field, $value){
      $q = "UPDATE ".TBL_PROFILE." SET ".$field." = '$value' WHERE username = '$username'";
  return mysql_query($q, $this->connection);
   }   ?>

 

Any suggestions.

Thank you!

 

it's either not submitting the values (maybe not retreiving them), or its just putting them in the wrong place. I've worked at this for weeks, I have no idea whats going on.

Link to comment
Share on other sites

Okay, I got most of it sorted. table USERS is not touched at all. I made an editProfile & editAccount

So table USERS and table PROFILE don't overlap anywhere.

 

Slogan, fullname, location, likes

are all inserted in the right place.

 

schooljob, status, dislikes, music

are not registering a value to be inserted.

Link to comment
Share on other sites

At the start of the first code you posted, you have got <?php and then the code after it is not php code. If you want to have that code in a php tag, you have to echo the lines and surround them with ""; You have no php closing tag for that part of the code, so just delete that first <?php instead.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.