title: MySql, Insert data to a table row from another table row (this row is just been created)
body: <p>Not sure how to describe my problem, but lets try..</p>
  
  <p>I am working on a small news portal php + mysql project
  I have two tables in mysql database.</p>
  
  <pre><code>1: news (
     n_id (primary key)
     n_title
     n_text
  )
  
  2: news_image (
     ni_id (primary key)
     n_id  (foreign key from news table)
     ni_name
     ni_caption
  )
  </code></pre>
  
  <p>(n_ prefix is for new and ni_ is prefix for news_image)</p>
  
  <p>news table will hold the news story and news_image table will store the names and captions for the images of the news. separate table for news images is because on later stage, i will be adding more than one images for each story. the script works fine (as i have tested it by entering data in data base through phpmyadmin.</p>
  
  <p><strong>Problem:</strong>
  I created a php script to add data to news table and to upload images to file system. it works fine. I used this query to add row to news table</p>
  
  <pre><code>INSERT INTO news
  SET
  n_title = '$title',
  n_text = '$text'
  </code></pre>
  
  <p>n_id is the primary key (integer and is AUTO_INCREMENT).. this works fine but I want a query that will execute just after the execution of above query and will automatically insert a new row in news_image table, taking n_id of the row that has just been inserted in news table. ni_name and ni_capption in news_image table is not a problem, I can get it easily but getting the n_id from news table of the newly inserted row is the problem... How can I get n_id...????? Please provide a detailed answer as I am newbie to php + mysql..
  Thanks for reading...waiting for reply..</p>