I'm making a script for inserting html pages into a database table. It's a 700-page ebook convert from pdf to html with the frames of page links on the left and navigation on the top.

Within the pages, I added textareas and a submit button within a form. Everything works. THe problem is that I need to do this manually clicking each page link on the left frame 700 times.

Since the forms on each page direct to a page where it inserts into the database table I need to put a redirect somehow that will lead to the next page. For example:

I have
http://localhost/ebooks/pg_0004.php

And I want to go to:
http://localhost/ebooks/pg_0005.php

I came up with the following script to go incrementally
http://localhost/ebooks/pg_0005.php
http://localhost/ebooks/pg_0006.php...


I'm open to any other suggestions on the script but how do I redirect to the next page automatically after the inserting into the database is finished?
PHP Code:
     $myarray explode('000'$previousurl);
        foreach(
$myarray as $value)
            {
                
$urlsnip $value;
            }
        
$thestringa $urlsnip[0] . $urlsnip[1] . $urlsnip[2] . $urlsnip[3] . $urlsnip[4];        
        
//echo $thestringa . '<br />';            
        
$thestringb $urlsnip[0] + $urlsnip[1] . $urlsnip[2] . $urlsnip[3] . $urlsnip[4];
        
//echo $thestringb . '<br />';
        
$newurl str_replace($thestringa$thestringb$previousurl);
        
        echo 
$newurl;
        
        
header'Location: ' $newurl ) ;
exit;