My form consists of 40 fields.
30 of them are normal text fields and 10 are file fields.
pos1 - pos10
recommend1 - recommend10
desc1 - desc10
image1 - image10 ( the file field!)
Once the user sibmits, I need all the data to upload into my MySQL db. Fine. However, I don't know how to upload multiple images to my server, and upload the image into the db with the correct name.
Please help as this is getting urgent.
Here is what I have so far...
for ( $i = 1; $i <= 10; $i++ ) {
$reclen = strlen ( $ {"recommend" . $i } ); // Ensure the Recommendation field is correct
if ( $reclen < 1 || $reclen > 65 ) {
echo "<script>alert(\"The Recommendation field at position $i is incorrectly completed. It must have information in it but not exceed 65 characters.\");history.go(-1)</script>\n";
exit;
}
$desclen = strlen ( $ {"desc" . $i } ); // Ensure the Description field is correct
if ( $desclen < 1 || $desclen > 65 ) {
echo "<script>alert(\"The Description field at position $i is incorrectly completed. It must have information in it but not exceed 100 characters.\");history.go(-1)</script>\n";
exit;
}
$vals[] = "('".mysql_escape_string(${"pos$i"})."','".mysql_escape_string(${"recommend$i"})."','".mysql_escape_string(${"desc$i"})."','".mysql_escape_string(${"image$i"})."')";
}
/* --------------------------------------------------------------------------------
--- Connect to the database ready to update the chart --
----------------------------------------------------------------------------- */
db_connect_cm(); // We are connected to the DB
$clear_sql = "DELETE FROM music";
$clear_result = mysql_query ( $clear_sql ); // Clear existing entries from the database table
if ( !$clear_result ) { // If failed go back to main page
session_destroy();
$msg = "Update Failed. The database table could not be emptied prior to the new upload. Please try again.";
$msg .= "<br>";
$msg .= mysql_error();
include ( "index.php" );
exit;
}
$update_sql = "INSERT INTO music (position, recommend, description) VALUES ".join(',', $vals); // Update the Music Chart Table
$update_result = mysql_query ( $update_sql );
if ( !$update_result ) { // If failed go back to main page
session_destroy();
$msg = "Update Failed. The new entries could not be uploaded into the database. Please try again.";
$msg .= "<br>";
$msg .= mysql_error();
include ( "index.php" );
exit;
}
I know the basic commands for uploading files to the server etc... but don't know whwre to fit them in my script, and as I say, how to upload multiple images in one go and enter their uploaded names into the db.