Jump to content

executing a query


Arnerd

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.