witt Posted May 28, 2006 Share Posted May 28, 2006 [code]$query = "INSERT INTO table_one (data) VALUES ('$data')";$result = mysql_query ($query);$counter = 3; for ($i = 0; $i < $counter; $i++) { $query = "INSERT INTO table_two (hello, data_id) VALUES ('$hello', '??????')"; $result = mysql_query ($query); }[/code]So basically the first query would insert $data into table_one under the data coulmn, and insert an incrementing number under the data_id column.What I want the second query to do is insert $hello into table_two under the hello column, and also insert the data_id generated by the first query into a column named data_id.I'm not quite sure how to use mysql_insert_id in this case but it should be simple. Quote Link to comment https://forums.phpfreaks.com/topic/10661-quick-mysql_insert_id-question/ Share on other sites More sharing options...
witt Posted May 28, 2006 Author Share Posted May 28, 2006 Never mind, I had it right all along. The problem was the I didn't put single quotes on the valuse I wanted to insert. Quote Link to comment https://forums.phpfreaks.com/topic/10661-quick-mysql_insert_id-question/#findComment-39790 Share on other sites More sharing options...
Barand Posted May 28, 2006 Share Posted May 28, 2006 The quotes are only mandatory with string values.[code]$query = "INSERT INTO table_one (data) VALUES ('$data')";$result = mysql_query ($query);$id = mysql_insert_id();$counter = 3; for ($i = 0; $i < $counter; $i++) { $query = "INSERT INTO table_two (hello, data_id) VALUES ('$hello', $id)"; $result = mysql_query ($query); }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10661-quick-mysql_insert_id-question/#findComment-39793 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.