CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 update table goes wrong

Print topic Send  topic

Author Message
miglio

Posts: 7
Posted: 06/01/2010, 2:02 AM

Hi all, I hope you'll help me..
I've a record through wich I insert values into a table.
Into this table there is a field called ID_SERVIZIO wich references the value ID into the table SERVIZI.
Now into my bug_tracker.ccs page I've added AfterExecuteInsert event because I must update 2 values of the just insert record, this is the code:
  
global $guasti;  
global $sql,$sql2,$db,$id_provider;  
global $Redirect;  
  
$db=new clsDBvoip();  
//inoltre devo prelevare dalla tabella servizi l'ID_PROVIDER relativo al servizio appena scelto  
$id_servizio=$guasti->id_servizio->GetValue();  
$sql2="SELECT id_provider FROM servizi WHERE id=".$db->ToSQL($id_servizio,ccsInteger);  
$db->query($sql2);  
$db->next_record();  
$id_provider=$db->f("id_provider");  
  
//$id=CCDLookUp("id","guasti","id=".$db->ToSQL($guasti->id->GetValue(),ccsInteger),$db);  
if(true) { //CCDLookUp("COUNT(*)","guasti","id"=$db->ToSQL($guasti->id->GetValue(),ccsInteger),$db) >0  
$sql="UPDATE guasti SET guasto=1,  
di_competenza_operatore=".$db->ToSQL($id_provider,ccsInteger)  
." WHERE id=".$db->ToSQL($guasti->id->GetValue(),ccsInteger);	  
$db->query($sql);  
$db->next_record();  
}else{$guasti->Errors->addError("Impossibile aggiornare il campo Guasto e Operatore!");}  
$db->close();  
The problem is the $sql2 query.
I think that It fails but I don't undestand Why?!!
Is it correct? and the update query, too?

Thanks, Mattia
View profile  Send private message
mamboBROWN


Posts: 1713
Posted: 06/01/2010, 8:55 PM

miglio,
Have you tested whether or not the generated SQL works by running it yourself within MySQL(query manager)? Why don't you echo out the generated SQL and see if you can get it to run. This way you can see what the error is directly. Give it a try and let me know what messages you get.
View profile  Send private message
miglio

Posts: 7
Posted: 06/03/2010, 1:00 AM

Quote mamboBROWN:
Have you tested whether or not the generated SQL works by running it yourself within MySQL(query manager)?
You mean that I should go to MysqlManager interface and update the table manually through the editor SQL?

Quote :
Why don't you echo out the generated SQL and see if you can get it to run. This way you can see what the error is directly. Give it a try and let me know what messages you get.
I've enabled the debugging mode into the db_mysql.php common file, but it doesn't show me the query into the Event.
It update the field EVASO but it doesn't update the field DI_COMPETENZA_OPERATORE ......

Miglio
View profile  Send private message
miglio

Posts: 7
Posted: 06/03/2010, 2:24 AM

The problem is linked to retrieving value from database...
I've no idea why this doesn't work!

Miglio
View profile  Send private message
magus

Posts: 98
Posted: 06/04/2010, 11:14 PM

Hi miglio,

A large part of your problem is that you aren't writing code with error checking, so that when it fails you are left guessing about what failed.

Best practise would be to familiarize yourself with the $Component->AddError ('Error Description Goes here functionality") and use it.


Here is an abstract example that might help:

// In the $Component event code

global $db; // a db connection that has been set up previously

// To test if there are errors
if($Component->Errors->Count() == 0) {
// YOUR CODE
}

// AND

if(!$db->query($sql) ) {

// If there is a db failure then ADD AN ERROR.

$Component->Errors->addError("Error - CUSTOM ERROR MESSAGE - blah blah ") ; }
}


Another method I use which (isn't best practice) but works well, is to temporarily insert code debug code

e.g.

$result = $db->($sql);

// Then print_r() the variables, arrays, components you want to investigate.

echo "<pre>";
echo "Result: ". $Result ."

db component:
";
print_r($db) ; //

exit();


The other thing to do is, as mamboBrown suggested, test the generated sql in something like phpMyAdmin or whatever you use.

I hope this helps.
Don A
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.