Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
query SQL update array
Old 05-13-2012, 03:19 AM query SQL update array
Experienced Talker

Posts: 31
Name: Ignatius Vinoth
Trades: 0
Dear Friends,

Im trying below code to update my user table but it doesn't work,

PHP Code:
$username $this->qls->make_safe($username);
  
$result $this->qls->SQL->select('*',
  
'users',
  array(
'username' =>
   array(
    
'=',
    
$username
   
)
  )
 );
 
$row $this->qls->SQL->fetch_array($result);
 
$this->qls->SQL->update('users',
   array(
    
'profile_photo' => $newfilename
   
),
   array(
'username' =>
    array(
     
'=',
     
$username
    
)
   )
  ); 
Your valuble suggestion is required.

Iggy
iggywiggy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-13-2012, 05:12 AM Re: query SQL update array
lizciz's Avatar
Super Spam Talker

Posts: 845
Name: Mattias Nordahl
Location: Sweden
Trades: 0
You have given too little information for us to do anything but guess. Just saying "it doesn't work" and showing some short code snippet isn't going to get you anywhere.

What is it that doesn't work? What should happen and what happens instead? Are there any error messages? What does the code mean, i.e. what does the different functions do and what do they look like (like the select() function)?
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 05-13-2012, 08:05 AM Re: query SQL update array
Experienced Talker

Posts: 31
Name: Ignatius Vinoth
Trades: 0
Dear Lizciz,

Sorry, Actually Im using this coding for upload of profile Image. Where Im trying to update my user table with the uploaded file name. File name not getting updated.

PHP Code:
function uploaded_file() {
 
$temporary_file_location $_FILES['upload']['tmp_name'];
 
$filename $_FILES['file']['name']; 
 
$file_ext strtolower(substr($_FILES['upload']['name'], -4));
 if ((
$file_ext == '.jpg') || ($file_ext == '.png') || ($file_ext == '.gif')){}
 
$newfilename rand() . $file_ext
 
$new_file_location $this->qls->main_directory '/profile_photo/' $newfilename;          
                 if (
$this->validate_existance()){
                 if (
$this->validate_size()){
                        if (
$this->validate_extensions()) {                  
   
// Is it an uploaded file? If so move it to the proper directory
   
if (is_uploaded_file($temporary_file_location)) {
   if (
move_uploaded_file($temporary_file_location$new_file_location)) { 
        
$username $this->qls->make_safe($username);
  
$result $this->qls->SQL->select('*',
  
'users',
  array(
'username' =>
   array(
    
'=',
    
$username
   
)
  )
 );
 
$row $this->qls->SQL->fetch_array($result);
 
$this->qls->SQL->update('users',
   array(
    
'profile_photo' => $newfilename
   
),
   array(
'username' =>
    array(
     
'=',
     
$username
    
)
   )
  );  
                                         
    return 
true;
    }    
    else {
    
$this->qls->User->add_page_error FILE_NOT_MOVED;
    return 
false;
    }
   }
   else {
  
$this->qls->User->add_page_error FILE_NOT_UPLOADED;
  return 
false;
  }   
  }
  else {
  
$this->qls->User->add_page_error FILE_EXTENSION_ERROR;
  return 
false;
  }
 }
 else {
   
$this->qls->User->add_page_error FILE_TOO_BIG;
   return 
false;
   }
}
  
else {
 
$this->qls->User->add_page_error FILE_EXISTS;
 return 
false;
 }

Please tell me any further information required.

BR,
Iggy
iggywiggy is offline
Reply With Quote
View Public Profile
 
Old 05-13-2012, 09:12 AM Re: query SQL update array
King Spam Talker

Posts: 1,090
Name: Paul W
Trades: 0
You're calling various methods to do the db queries - we need to see those.

I can't see why you're messing around with unusual string arrays in the code you have given or where you're getting $username from. Read up on associative arrays anyway but you don't need them here - just pass the filename/username as args to the called methods.
__________________
Great music:
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 05-13-2012, 12:12 PM Re: query SQL update array
Experienced Talker

Posts: 31
Name: Ignatius Vinoth
Trades: 0
Dear PaulW,

Sorry to tell you Im not really from programming line. Im from Telecom.
Jus trying to bring up my own site.

Quote:
You're calling various methods to do the db queries - we need to see those.

I can't see why you're messing around with unusual string arrays in the code you have given or where you're getting $username from. Read up on associative arrays anyway but you don't need them here - just pass the filename/username as args to the called methods.
really not able to understand what you mean to say??? Even I tried simple update query still it don't work at all. If you don't mind can you please clear it again. soory for the inconvenience.

BR,
Iggy
iggywiggy is offline
Reply With Quote
View Public Profile
 
Old 05-13-2012, 12:26 PM Re: query SQL update array
Experienced Talker

Posts: 31
Name: Ignatius Vinoth
Trades: 0
*Sorry*
iggywiggy is offline
Reply With Quote
View Public Profile
 
Old 05-13-2012, 02:18 PM Re: query SQL update array
Experienced Talker

Posts: 31
Name: Ignatius Vinoth
Trades: 0
Hi,

Even tried,

PHP Code:
$Query mysql_query("UPDATE qls3_users SET 
                        `profile_photo`='
$newfilename'
                         WHERE `id`='
$id'") or die(mysql_error()); 
still it is not updating......

Iggy
iggywiggy is offline
Reply With Quote
View Public Profile
 
Old 05-13-2012, 03:04 PM Re: query SQL update array
lizciz's Avatar
Super Spam Talker

Posts: 845
Name: Mattias Nordahl
Location: Sweden
Trades: 0
When you did this last try, did you get any errors from mysql_error() or did it just not update the value? Have you actually checked the value before and after to see that it did not change?

Have you checked that the $newfilename and $id variables have the values you'd expect? Try i.e. to dump them with
PHP Code:
var_dump($newfilename$id
You should try to narrow down where the error occurs. Add some debug echos here and there to verify that all variables have the expected values and that functions returns what they should.

As an example:
PHP Code:
// ...
$a get_a_number();
$b 6;
var_dump($a$b); // check what values they have

$c add_numbers($a$b);
var_dump($c);

// ... 
Lets say $a is 3 and $b is 6, then $c should be 9. But $c is 13, then that would tell you that the error lies somewhere in the function add_numbers().

PHP Code:
// ...
$a get_mood();
if (
$a == "happy") {
    
do_something();
    echo 
"1"// some simple debug
} else {
    
do_something_else();
    echo 
"2";
}
// ... 
Lets say $a should be "happy", but the script echoes "2", that tells you that there's probably something wrong with the function get_mood().

After you've narrowed down the error, you might spot the problem yourself, or else you will at least have more information to give here on the forum and someone might be able to help you further.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 05-13-2012, 03:58 PM Re: query SQL update array
King Spam Talker

Posts: 1,090
Name: Paul W
Trades: 0
Hi Iggy, I was trying to say "there's more php somewhere, can we see it" The form that's being processed would also be useful - you're mentioning a username and an id in your posts and I'm wondering where they come from.
__________________
Great music:
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 05-14-2012, 12:21 PM Re: query SQL update array
Experienced Talker

Posts: 31
Name: Ignatius Vinoth
Trades: 0
Dear Paul/Lizciz,

Im totally confused with my coding itself. Now Im planning to change the coding completely for upload. Let me check whether it works or not? If it doesn't, I will come back for help. Sorry for now & thanks for your support.

Iggy
iggywiggy is offline
Reply With Quote
View Public Profile
 
Old 05-15-2012, 04:42 AM Re: query SQL update array
Experienced Talker

Posts: 31
Name: Ignatius Vinoth
Trades: 0
Dear Paul/Lizciz,

I fixed the problem. You people are really gr8.
Mistake I did was I haven't gave username info in my form.
I was simply fetching the user info in air...lol.

Thanks for you valuable support.
I got a long way to go. I will get back to you again & again now...

BR,
Ignatius
iggywiggy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to query SQL update array
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.37141 seconds with 11 queries