thugsr Posted November 27, 2012 Share Posted November 27, 2012 Hi everybody, i have class with some variables and insert function, but when i call insert function in database are inserted empty values, just id (AUTO INCREMENT) has value other cells are emtpy... My class is: <?php include ('db_fns.php'); class preduzece { public $naziv_preduzeca; public $sifra_mesta; public $ulica; public $broj; public $opis; public $sifra_delatnosti; public $sifra_usluge; public $aktivno; public function dodaj_preduzece ($preduzece) { $query = "INSERT INTO preduzece (naziv_preduzeca, sifra_mesta, ulica, broj, opis, sifra_delatnosti, aktivno) VALUES ('$preduzece->naziv_preduzeca','$preduzece->sifra_mesta','$preduzece->ulica','$preduzece->broj', '$preduzece->opis','$preduzece->sifra_delatnosti','$preduzece->aktivno')"; $result = mysql_query($query) or die("Doslo je do greske prilikom unosa preduzeca:" .mysql_error()); // insert } } ?> And in other page i use it (have form from witch i collect values for db): include("scripts/preduzece_fns.php") $firma=new preduzece() ; $firma->ulica=$_POST['ulica']; $firma->broj=$_POST['broj']; $firma->ulica= mysql_real_escape_string( $firma->ulica ); $firma->broj= mysql_real_escape_string( $firma->broj ); $firma->naziv_preduzeca = $_POST["naziv_preduzeca"]; $firma->naziv_preduzeca = mysql_real_escape_string( $firma->naziv_preduzeca ); $firma->sifra_mesta = $_POST["mesto"]; $firma->opis = $_POST["opis"]; $firma->opis= mysql_real_escape_string( $firma->opis ); $firma->sifra_delatnosti = $_POST["delatnost"]; $firma->aktivno = $_POST["aktivno"]; $firma->dodaj_preduzece(); when i echo $firma->naziv_preduzeca or anything else values are collected from form, only when i call function dodaj_preduzece something goes wrong... Does anybody know why this is happening? Ps sorry for grammar errors if i have it (I am from Serbia ) Link to comment https://forums.phpfreaks.com/topic/271238-my-insert-function-are-inserting-empty-values-in-database/ Share on other sites More sharing options...
Muddy_Funster Posted November 27, 2012 Share Posted November 27, 2012 change all instances of $preduzece-> to $this-> and remove $preduzece from between the parenthesis of the function decleration. Then I recomend you go do some more learning on classess and objects. Link to comment https://forums.phpfreaks.com/topic/271238-my-insert-function-are-inserting-empty-values-in-database/#findComment-1395479 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.