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
Problem with updating database
Old 10-26-2008, 01:01 AM Problem with updating database
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Hey I'm having trouble with updating my database.
I have no idea why it isnt.. because its not displaying any errors.

The form posts the variables perfectly, then the page puts the information into the function page with
PHP Code:
<?
if ($functions->assignProject($_GET['allocate'], $_GET['ID'])) {
  
header("Location: index.php");
}
?>
Then this is the function page.
PHP Code:
function assignProject($allocate$ID) {
     
$this->sql->Update("UPDATE ".$this->TABLES['projects']." SET assigned = '".$allocate."', WHERE id = $ID");
    return 
true;
  } 
It returns true as though its updated assigned. But when I check the database manually the figures are still the same.

I have checked the form is sending the variables, the information is getting to the function page. its just not updating properly.
This is the SQL Update query

PHP Code:
function Update($sql)    {
        if ((empty(
$sql)) || (!eregi("^update",$sql)) || (empty($this->CONNECTION))) {
      
$this->ERROR_MSG "\r\n" "SQL Statement is <code>null</code> or not an UPDATE - " date('H:i:s');
      
$this->debug();
      return 
false;
    } else {
          
$conn $this->CONNECTION;
          
$results mysql_query($sql,$conn);
          if (!
$results) {
        
$this->ERROR_MSG "\r\n" mysql_error()." - " date('H:i:s');
        
$this->debug();
        return 
false;
      } else {
            return 
mysql_affected_rows();
      }
    }
    } 
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-26-2008, 03:25 PM Re: Problem with updating database
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
try:

PHP Code:
<?
if (functions->assignProject($_GET['allocate'], $_GET['ID']) == true) {
  
header("Location: index.php");
} else {
echo 
"SOMETHING_WRONG";
}
?>
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 10-26-2008, 04:41 PM Re: Problem with updating database
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Quote:
Originally Posted by rogem002 View Post
try:

PHP Code:
<?
if (functions->assignProject($_GET['allocate'], $_GET['ID']) == true) {
  
header("Location: index.php");
} else {
echo 
"SOMETHING_WRONG";
}
?>
There is no fault in this part of the problem. Because I can get the function to echo back $ID and $allocate with the correct values.
Problem seems to be when its actually trying to update the database. Its not actually updating it.

Still does the same thing, takes me to index.php but doesnt actually update the database.

This is ment to give someone a project from a list of ones that havent been allocated. So when it assigns it it takes it from the unallocated projects and adds it to the persons list.

Thats whats getting changed in the database. TABLES['projects']." SET assigned = '".$allocate."' well, its ment to.

I cant see anything wrong with the update sql line.
Its coming back true, but it isnt working.

Is there a way to test to see if it comes back false?
__________________
Websites Created;
warscope.com
ratepayers.org.nz

Last edited by lothop; 10-26-2008 at 09:41 PM..
lothop is offline
Reply With Quote
View Public Profile
 
Old 10-26-2008, 09:54 PM Re: Problem with updating database
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Sorry for so many replies.

I have tried changing the function and how it updates with a couple of syntax changes.
PHP Code:
function assignProject($allocate$ID) {
     
$this->sql->Update("UPDATE ".$this->TABLES['projects']." SET assigned = $allocate WHERE id = $ID");
    return 
true;
  } 
I'm not getting returned back to index.php now.
I get the error -
Unknown column 'DawnForge' in 'field list' - 18:52:57done

$allocate = DawnForge
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
Old 10-27-2008, 02:58 AM Re: Problem with updating database
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
PHP Code:
    function assignProject($allocate$ID) {
     
$this->sql->Update("UPDATE ".$this->TABLES['projects']." SET assigned = '".$allocate."' WHERE id = $ID");
    return 
true;
  } 
PHP Code:
<?
require('inc/header.inc.php');
if (
$SZUserMgnt->assignProject($_GET['allocate'], $_GET['ID']) == true) {
  
header("Location: index.php");
} else {
echo 
"SOMETHING_WRONG";
}
?>


And it works, for some reason it worked. I have no idea why... just suddenly worked...
Only thing I can see is I removed a , in the update function...

Could that be the reason?
Thankyou for your help, added to your talkthingy
__________________
Websites Created;
warscope.com
ratepayers.org.nz

Last edited by lothop; 10-27-2008 at 03:00 AM..
lothop is offline
Reply With Quote
View Public Profile
 
Old 10-27-2008, 05:06 AM Re: Problem with updating database
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
if $allocate is a string it will need single quotes around it.

the difference between the code in post #4 and post #5 is the single quotes have been added

SET assigned = $allocate WHERE

SET assigned = '".$allocate."' WHERE
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-27-2008, 05:46 PM Re: Problem with updating database
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Yes but in the first post I originally had them in it.

But i think the , stopped it from working correctly
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Problem with updating database
 

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.48308 seconds with 12 queries