Page 1 of 1

foreach question

Posted: Sat Mar 18, 2006 7:30 pm
by a94060
hi,i have this code over here

Code: Select all

$q = array(
"1" => "INSERT INTO reg_users (user_id,username,password,registered,email) VALUES ('', '$name' , '$password' , '$time' , '$email')",
 2 => "INSERT INTO profile (username, Name, Location, Gender, Birth_date, registered, profile_pic) VALUES('$name' , 'Name', 'Location', 'Gender', 'Birth Date', $time, 'Picture URL.')",
 3 => "INSERT INTO style (main_HEADER_text, main_bgcolor, main_HEADER_fontcolor, main_fontstyle, main_fontface, border_color, border_style, border_size, mod_titlebarBG, mod_titlefontcolor, mod_titlefontface, username) VALUES
('$name', 'White', 'Black', 'Bold', 'Verdana', 'Black', 'Solid', '1', 'White', 'Black', 'Verdana', )")


the thing i want to do is foreach of the of the array vaules,i want the database to do the query.

how can i acheave this?

Posted: Sat Mar 18, 2006 7:40 pm
by wtf

Code: Select all

foreach($q as $query) {
    mysql_query($query);
}

Posted: Sat Mar 18, 2006 7:42 pm
by a94060
i had put that in my zend program and it kept saying something like unexpected thing at end of line. is the array correct? like is everyhtin gin there correct?

Posted: Sat Mar 18, 2006 9:27 pm
by josh
I've never gotten an "unexpected thing at end of line" error, are you sure it said "undexpected thing"?

Posted: Sat Mar 18, 2006 9:29 pm
by a94060
it didnt say thing,i for got what it said there though. :lol:

Posted: Sat Mar 18, 2006 11:26 pm
by wtf
well...

it may have said 'unexpected thing'. You have issues in your sql strings... for example

Your first array key is string and rest of them are ints. Not sure if that woud cause problem but I'd keep it consistent.

Your first sql statement

Code: Select all

"INSERT INTO reg_users (user_id,username,password,registered,email) VALUES ('', '$name' , '$password' , '$time' , '$email')"
You are inserting empty user_id... That will probably crash if your user_id is primary key

Last sql statement

Code: Select all

"INSERT INTO style (main_HEADER_text, main_bgcolor, main_HEADER_fontcolor, main_fontstyle, main_fontface, border_color, border_style, border_size, mod_titlebarBG, mod_titlefontcolor, mod_titlefontface, username) VALUES
('$name', 'White', 'Black', 'Bold', 'Verdana', 'Black', 'Solid', '1', 'White', 'Black', 'Verdana', )"
You have 12 rows in your insert into and only 11 in values.
Right after 'Verdana' you have a comma which will cause problems. You need one more field to complete this.

I'd first make sure sql statements execute correctly then continue. Errors are there to help you debug not to be ignored. They'll bite you in the A55