CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 after insert event, sql statements cannot be executed

Print topic Send  topic

Author Message
orafrijoles

Posts: 4
Posted: 08/15/2005, 5:51 PM

Hi there! i have little experience on CCS so i want to be assisted.
Here's my problem :
I'm using a record page to fill one table, two fields of this table are going to be inserted later in another table, an intermediate table that is. So i thought was a good idea to call an 'after insert event' on the server and make the two insertions on my intermediate table. Here's what i've tried :
  
	function partidos_AfterInsert()  
	{  
	    $partidos_AfterInsert = true;  
	  
	    global $partidos;  
	    // Write your own code here.  
	    $db = new clsRecordPartidos();  
	   $SQL = "INSERT INTO partidos_has_equipos (par_clv,equ_clv) "  
	         ."VALUES (LAST_INSERT_ID(),".CCGetFromPost("par_eqlocal",0)."); "  
			 . "INSERT INTO partidos_has_equipos (par_clv,equ_clv) "  
	         ."VALUES (LAST_INSERT_ID(),".CCGetFromPost("par_eqvisita",0)."); ";  
	  
	 	 $db->query($SQL);  
	 	 $db->close();  
	  
	//End Custom Code  
	  
	  
	    return $partidos_AfterInsert;  
	}  
	
I've tried changing several details in this part of the code yet not finding the correct. I get errors like 'undefined function query()' that means that $db var is not a valid connection object. I also wonder what global $partidos variable means...

I've seen many examples on this forum but i can't get to fix my code.
I hope someone can help me here. Thanks.

_________________
Sable y machete
View profile  Send private message
DonB
Posted: 08/16/2005, 8:16 AM

It should be clsDBRecordPartidos(), I believe. (note the addition of "DB" to
the name)

--
DonB

http://www.gotodon.com/ccbth


"orafrijoles" <orafrijoles@forum.codecharge> wrote in message
news:5430138ab078de@news.codecharge.com...
> Hi there! i have little experience on CCS so i want to be assisted.
> Here's my problem :
> I'm using a record page to fill one table, two fields of this table are
going
> to be inserted later in another table, an intermediate table that is. So i
> thought was a good idea to call an 'after insert event' on the server and
make
> the two insertions on my intermediate table. Here's what i've tried :
>
  
> function partidos_AfterInsert()  
> {  
>     $partidos_AfterInsert = true;  
>  
>     global $partidos;  
>     // Write your own code here.  
>     $db = new clsRecordPartidos();  
>    $SQL = "INSERT INTO partidos_has_equipos (par_clv,equ_clv) "  
>          ."VALUES (LAST_INSERT_ID(),".CCGetFromPost("par_eqlocal",0)."); "  
> . "INSERT INTO partidos_has_equipos (par_clv,equ_clv) "  
>          ."VALUES (LAST_INSERT_ID(),".CCGetFromPost("par_eqvisita",0).");  
";  
>  
> $db->query($SQL);  
> $db->close();  
>  
> //End Custom Code  
>  
>  
>     return $partidos_AfterInsert;  
> }  
> 
> I've tried changing several details in this part of the code yet not
finding
> the correct. I get errors like 'undefined function query()' that means
that $db
> var is not a valid connection object. I also wonder what global $partidos
> variable means...
>
> I've seen many examples on this forum but i can't get to fix my code.
> I hope someone can help me here. Thanks.
>
> _________________
> Sable y machete
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

orafrijoles

Posts: 4
Posted: 08/16/2005, 10:27 AM

Yeah i found the problem !

I just pick up the db class created in the common.php and my new code look like this. Any suggestions are welcome :

  
    global $partidos;  
	global $conexion;  
  
	$conexion = new clsDBtrinca();  
  
    // Write your own code here.  
	$last_id = mysql_insert_id();   // Obtiene el ultimo ID insertado en par_clv  
  
	// INICIO : rellenar partidos_has_equipos	  
	$eqlocal = $partidos->ds->eq_local->GetValue();  
	$eqvisita = $partidos->ds->eq_visita->GetValue();  
  
	$sql = "INSERT INTO partidos_has_equipos ("  
			 . "par_clv, "  
			 . "equ_clv"   
			 . ") VALUES (".$last_id.",".$conexion->ToSQL($eqlocal,ccsInteger). "); ";  
	$conexion->query($sql);		   
	$sql = "INSERT INTO partidos_has_equipos ("  
			 . "par_clv, "  
			 . "equ_clv"   
			 . ") VALUES (".$last_id.",".$conexion->ToSQL($eqvisita,ccsInteger). "); ";  
	  
	  if($conexion->Errors->Count() == 0) {  
            $conexion->query($this->SQL);  
          
      } else {  
		die ("Error al agregar partidos : ".mysql_error());  
	  }  
  

See ya
_________________
Sable y machete
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.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


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