well, your trying to get the insert_id() without running the query first. so you have to add:
mysql_query($query); before: $art_id = mysql_insert_id(); also, your foreach loop should be: foreach ($media_types as $type) (without the brackets []) i am assuming $media_types is an array already. jack jackson wrote:
Whoops. I must be botching this syntax because this is printing",,0,," as the query: All the first part of the query works and inserts records into the database, and it's when I try to get mysql_insert_id () that I seem to run into trouble. Ah. ave I not yet run the first query? The part of the code that actually runs it was given to me in a class and I don't quite understand how it's suppose to be working ... Thanks in advance: $trimblog = (trim($_POST['blog'])); $blog = (nl2br($trimblog));$image = mysql_real_escape_string($final_imgname); $image_thb = mysql_real_escape_string($final_thb_filename);$pubwidth = mysql_real_escape_string(trim($_POST['art_width'])); $pubheight = mysql_real_escape_string(trim($_POST['art_height'])); $origwidth = mysql_real_escape_string(trim($_POST['orig_width'])); $origheight = mysql_real_escape_string(trim($_POST['orig_height'])); $publisher = mysql_real_escape_string(trim($_POST['publisher'])); $series = mysql_real_escape_string(trim($_POST['series'])); $subject = mysql_real_escape_string(trim($_POST['subject'])); $title = mysql_real_escape_string(trim($_POST['title'])); $caption = mysql_real_escape_string(trim($_POST['art_caption'])); $blog = mysql_real_escape_string($blog); $keywords = mysql_real_escape_string(trim($_POST['keywords'])); $query = "INSERT INTO art (art_id,art_thumbnail, art_image, art_width, art_height, orig_width, orig_height, art_pub_date, publisher_id, art_creation_date, series_id, subject_id, art_title, art_caption, art_keywords, art_blog) VALUES ('','" . $image_thb . "','" . $image . "','" . $pubwidth . "','" . $pubheight . "','" . $origwidth . "','" . $origheight . "','" . $pubdate . "','" . $publisher . "','" . $orig_date . "','" . $series . "','" . $subject . "','" . $title . "','" . $caption . "','" . $keywords . "','" . $blog . "')"; $art_id = mysql_insert_id(); foreach ($media_types[] as $type) { $query .= "INSERT INTO media_art (media_art_id,media_id, art_id) VALUES ('','" . $type . "','" . $art_id . "')"; // perform query here } if (!mysql_query($query) || mysql_error($query)!= ''){ $errMsg = mysql_error($query); trigger_error("Problem with addrecord: $query\r\n$errMsg\r\n", E_USER_ERROR); } else { $msgText = '<tr><td><strong>Your record was saved!</strong></td></tr>'; } On 6/9/05, Richard Davey <[EMAIL PROTECTED]> wrote:Hello jack, Friday, June 10, 2005, 2:16:06 AM, you wrote: jj> $query = "INSERT INTO media_art (media_art_id,art_id, media_id) jj> VALUES ('','" . $art_id . "','" . $media_types[2]. "')"; jj> repeat as many or few times as possible to account for the number of jj> checked boxes, such as One way: for ($i = 0; $i < count($media_types); $++) { $query = "INSERT INTO media_art (media_art_id,art_id, media_id) VALUES ('','$art_id','{$media_types[$i]}')"; // perform query here } Another: foreach ($media_types as $type) { $query = "INSERT INTO media_art (media_art_id,art_id, media_id) VALUES ('','$art_id','$type')"; // perform query here } Best regards, Richard Davey -- http://www.launchcode.co.uk - PHP Development Services "I do not fear computers. I fear the lack of them." - Isaac Asimov -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

