Arnerd Posted February 8, 2010 Share Posted February 8, 2010 hello all im new to learning php, and i am stuck on executing a query $fieldlist = ""; $updatelist = ""; foreach ($_SESSION['input'] as $key => $val) { $fieldlist .= $key. ','; $updatelist .= "'".$val."',"; } $fieldlist = substr($fieldlist, 0, strlen($fieldlist)-1); $updatelist = substr($updatelist , 0, strlen($updatelist )-1); $query = "INSERT INTO leden ( ".$fieldlist.") VALUES ( ".$updatelist.")"; $db->exec($query); when i echo fieldlist and updatelist i get gebruikersnaam,voornaam,achternaam,email,email2,postcode,woonplaats,geboortejaar 'dfgsdf','sdfqf','dsfqsdf','[email protected]','[email protected]','4655','berf','2010' and when i exec the code above, i get; Fatal error: Call to a member function exec() on a non-object any help on this would be greatly appreciated thx in advance Link to comment https://forums.phpfreaks.com/topic/191320-executing-a-query/ Share on other sites More sharing options...
trq Posted February 8, 2010 Share Posted February 8, 2010 Where do you define $db ? Link to comment https://forums.phpfreaks.com/topic/191320-executing-a-query/#findComment-1008705 Share on other sites More sharing options...
Arnerd Posted February 8, 2010 Author Share Posted February 8, 2010 i have a db_config.php file, wich is included once in the registration form <?php $db = array ( 'host' => 'localhost', 'user' => 'root', 'pass' => '', 'dbname' => 'buxus' ); if(!mysql_connect($db['host'], $db['user'], $db['pass'])) { trigger_error('Fout bij verbinden: '.mysql_error()); } elseif(!mysql_select_db($db['dbname'])) { trigger_error('Fout bij selecteren database: '.mysql_error()); } else { $sql = "SET SESSION sql_mode = 'ANSI,ONLY_FULL_GROUP_BY'"; if(!mysql_query($sql)) { trigger_error('MySQL in ANSI niet mogelijk'); } } ?> Link to comment https://forums.phpfreaks.com/topic/191320-executing-a-query/#findComment-1008707 Share on other sites More sharing options...
trq Posted February 8, 2010 Share Posted February 8, 2010 I'm not sure where you got the idea that $db was a connection object then, its simply an array containing your connection details. Your not even using any database object. This... $db->exec($query); Should be.... mysql_query($query); Link to comment https://forums.phpfreaks.com/topic/191320-executing-a-query/#findComment-1008735 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.