I have made a simple register-form for my users.
All the things worked fine, untill I wanted to insert the user's info in my database.
I first used something like this:
mysql_query("INSERT INTO db (id, username) VALUES ('$id', '$user')
That worked okey, but it costed so much space, so I wanted to make it smaller.
All the user's information is stored in a database called $member.
It looks like this:
$member = array('id' => $this->id, 'username' => $this->user, 'password' => $this->password,);
That works fine too, but now I want to make two arrays containing all the information, and than insert it into the database. So I made another function:
function make_db_data($data) {
$field_names = "";
$field_values = "";
foreach ($data as $key => $value) {
$value = preg_replace("/'/", "\\'", $value);
$field_names .= " $key, ";
$field_values .= " '$value', ";
}
$field_names = preg_replace( "/,$/", "", $field_names );
$field_values = preg_replace( "/,$/", "", $field_values );
return array( 'FIELD_NAMES' => $field_names,
'FIELD_VALUES' => $field_values, );
}
The INSERT-function would like this:
$db_thing = make_db_data($member);
$insert = mysql_query("INSERT INTO db (".$db_thing['FIELD_NAMES'].") VALUES(".$db_thing['FIELD_VALUES'].")");
But this isn't working... Why not? I don't know!
I do not get an error on this, and it doesn't update the database.
So anyone know what I have to do? Or someone has an other good script?