Jump to content

Recommended Posts

Ok so the following pieces of code work in the order I shal post them. Passing information from one piece to another, in order to eventually change a field in the DB.

 

 

This is the initial form the user enters into

<form action="process.php" method="POST" class="style1">
<table align="center" width="90%" style='border: 1px dotted;' bgcolor="#eeeeee" cellspacing="0" cellpadding="3">

<tr>
   <td>Xbox360gt:</td>
   <td><input type="text" name="x360gt" value="<?php if($form->value("x360gt") == "") {echo $session->userinfo['x360gt'];} else {echo $form->value("x360gt");} ?>" /></td>
   <td><?php echo $form->error("x360gt"); ?></td>
</tr>
<tr><td colspan="2" align="right">
<input type="hidden" name="subedit" value="1">
<input type="submit" value="Edit Gamertag"></td></tr>
<tr><td colspan="2" align="left"></td></tr>
</table>
</form>

 

Then

   function procEditAccountGT(){
      global $session, $form;
      // Account edit attempt 
      $retval = $session->editAccountGT($_POST['x360gt']);

      //Account edit successful 
      if($retval){
         $_SESSION['usersettings'] = true;
	   $session->referrer .= (preg_match('#\?#', $session->referrer)) ? '&user='.$session->username : '?user='.$session->username;
         header("Location: ".$session->referrer);
      }
      // Error found with form 
      else{
         $_SESSION['value_array'] = $_POST;
         $_SESSION['error_array'] = $form->getErrorArray();
	 $session->referrer .= (preg_match('#\?#', $session->referrer)) ? '&user='.$session->username : '?user='.$session->username;
         header("Location: ".$session->referrer);
      }
   }

 

Then

   function editAccountGT($subx360gt){
      global $database, $form;  //The database and form object

  
  
  
  /*360 gt error checking */
$field = "x360gt";     
if(!$subx360gt || strlen($subx360gt = trim($subx360gt)) == 0){       
  $form->setError($field, "* gamertag not entered");     
}         
  $subx360gt = stripslashes($subx360gt);
  

      
      /* Errors exist, have user correct them */
      if($form->num_errors > 0){
         return false;  //Errors with form
      }
      	  
  //change xbox360 gamertag
  if($subx360gt) {
   $database->updateUserField($this->username,"x360gt",$subx360gt);
}

      
      /* Success! */
      return true;
   }

 

And finally

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

 

My problem is the data is not being altered in the DB, could anyone help me here? I have spent around an hour trying to work the problem out. THankyou

Link to comment
https://forums.phpfreaks.com/topic/169077-solved-edit-a-field/
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.