Jump to content
Larry Ullman's Book Forums

alexandra

Members
  • Content Count

    3
  • Joined

  • Last visited

Community Reputation

0 Neutral

About alexandra

  • Rank
    Newbie
  1. Hi: I am trying to figure out a way to send data to multiple SQL databases on two separate servers, and I did come across a couple of scripts that I have modified to my scripts, but I still can't get this to work with the mysql_connect.php. Any ideas how to have multiple database connections on one script? Thanks in advance. Here are the scripts I'm using from Larry's book... --------------------------------------------------------------------------------------------------------- <?php # Script 12.8 - add_file.php // This page allows users to upload files to the server. // Set the page title and include the HTML header. $page_title = 'Upload a File'; include ('./includes/header.html'); if(!isset($_SESSION['user_id'])){ session_unset(); session_destroy(); header("Location:../login.php"); exit; } $counter = 1; // Number of files to allow for. if (isset($_POST['submitted'])) { // Handle the form. require_once ('./mysql_connect.php'); // Connect to the database. for ($i = 0; $i < $counter; $i++) { // Handle each uploaded file. // Create index names to refer to the proper upload and candidate information. $firstname = 'firstname' . $i; $lastname = 'lastname' . $i; $email = 'email' . $i; $citizenship = 'citizenship' . $i; $location = 'location' . $i; $filename = 'upload' . $i; // Check for a file. // Check for a first name (not required). if (!empty($_POST[$firstname])) { $f = "'" . escape_data($_POST[$firstname]) . "'"; } else { $f = 'NULL'; } // Check for a last name (not required). if (!empty($_POST[$lastname])) { $l = "'" . escape_data($_POST[$lastname]) . "'"; } else { $l = 'NULL'; } // Check for a email (not required). if (!empty($_POST[$email])) { $e = "'" . escape_data($_POST[$email]) . "'"; } else { $e = 'NULL'; } // Check for a citizenship (not required). if (!empty($_POST[$citizenship])) { $c = "'" . escape_data($_POST[$citizenship]) . "'"; } else { $c = 'NULL'; } // Check for a first name (not required). if (!empty($_POST[$location])) { $o = "'" . escape_data($_POST[$location]) . "'"; } else { $o = 'NULL'; } if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] != 4)) { // Add the record to the database. $query = "INSERT INTO uploads (file_name, file_size, file_type, firstname, lastname, email, citizenship, location) VALUES ('{$_FILES[$filename]['name']}', {$_FILES[$filename]['size']}, '{$_FILES[$filename]['type']}', $f, $l, $e, $c, $o)"; $result = mysql_query ($query); if ($result) { // Return the upload_id from the database. $upload_id = mysql_insert_id(); // Move the file over. if (move_uploaded_file($_FILES[$filename]['tmp_name'], "../uploads_stews/$upload_id")) { echo '<p><br><h2><strong>Thank you. Your CV has successfully been uploaded!</h2></strong></p>'; } else { // File could not be moved. echo '<p><font color="red">Your CV could not be uploaded. Either your image was too large (over 500kb) or you forgot to add the file. Please try again..</font></p>'; // Remove the record from the database. $query = "DELETE FROM uploads WHERE upload_id = $upload_id"; $result = mysql_query ($query); // Add more detailed error reporting, if desired. } } else { // If the query did not run OK. echo '<p><font color="red">Your submission could not be processed due to a system error. We apologize for any inconvenience.</font></p>'; // Print the query and invoke the mysql_error() function to debug. } } // End of if (isset($the_file)... } // End of FOR loop. mysql_close(); // Close the database connection. } // End of the main Submit conditional. ?> <form enctype="multipart/form-data" action="add_file_thankyou.php" method="post"> <fieldset><legend>Fill out the form to upload a file:</legend> <input type="hidden" name="MAX_FILE_SIZE" value="524288"> <?php // Create the inputs. for ($i = 0; $i < $counter; $i++) { echo '<p><b>First Name:</b> <input type="text" name="firstname' . $i . '" size="20"</p> <p><b>Last name:</b> <input type="text" name="lastname' . $i . '" size="20"></p> <p><b>Email Address:</b> <input type="text" name="email' . $i . '" size="20"></p> <p><b>Nationality:</b> <input type="text" name="citizenship' . $i . '" size="20"></p> <p><b>Your Current Location:</b> <input type="text" name="location' . $i . '" size="20"></p> <p><b>Upload Your CV:</b> <input type="file" name="upload' . $i . '" /></p> '; } ?> </fieldset> <input type="hidden" name="submitted" value="TRUE" /> <div align="center"><input type="submit" name="submit" value="Submit" /></div> </form> <?php include ('./includes/footer.html'); ?> ------------------------------------------------------------------------------------------------------------ and the add_file script ------------------------------------------------------------------------------------------------------------ <?php # Script 12.8 - add_file.php // This page allows users to upload files to the server. // Set the page title and include the HTML header. $page_title = 'Upload a File'; include ('./includes/header.html'); if(!isset($_SESSION['user_id'])){ session_unset(); session_destroy(); header("Location:../login.php"); exit; } $counter = 1; // Number of files to allow for. if (isset($_POST['submitted'])) { // Handle the form. require_once ('./mysql_connect.php'); // Connect to the database. for ($i = 0; $i < $counter; $i++) { // Handle each uploaded file. // Create index names to refer to the proper upload and candidate information. $firstname = 'firstname' . $i; $lastname = 'lastname' . $i; $email = 'email' . $i; $citizenship = 'citizenship' . $i; $location = 'location' . $i; $filename = 'upload' . $i; // Check for a file. // Check for a first name (not required). if (!empty($_POST[$firstname])) { $f = "'" . escape_data($_POST[$firstname]) . "'"; } else { $f = 'NULL'; } // Check for a last name (not required). if (!empty($_POST[$lastname])) { $l = "'" . escape_data($_POST[$lastname]) . "'"; } else { $l = 'NULL'; } // Check for a email (not required). if (!empty($_POST[$email])) { $e = "'" . escape_data($_POST[$email]) . "'"; } else { $e = 'NULL'; } // Check for a citizenship (not required). if (!empty($_POST[$citizenship])) { $c = "'" . escape_data($_POST[$citizenship]) . "'"; } else { $c = 'NULL'; } // Check for a first name (not required). if (!empty($_POST[$location])) { $o = "'" . escape_data($_POST[$location]) . "'"; } else { $o = 'NULL'; } if (isset($_FILES[$filename]) && ($_FILES[$filename]['error'] != 4)) { // Add the record to the database. $query = "INSERT INTO uploads (file_name, file_size, file_type, firstname, lastname, email, citizenship, location) VALUES ('{$_FILES[$filename]['name']}', {$_FILES[$filename]['size']}, '{$_FILES[$filename]['type']}', $f, $l, $e, $c, $o)"; $result = mysql_query ($query); if ($result) { // Return the upload_id from the database. $upload_id = mysql_insert_id(); // Move the file over. if (move_uploaded_file($_FILES[$filename]['tmp_name'], "../uploads_stews/$upload_id")) { echo '<p><br><h2><strong>Thank you. Your CV has successfully been uploaded!</h2></strong></p>'; } else { // File could not be moved. echo '<p><font color="red">Your CV could not be uploaded. Either your image was too large (over 500kb) or you forgot to add the file. Please try again..</font></p>'; // Remove the record from the database. $query = "DELETE FROM uploads WHERE upload_id = $upload_id"; $result = mysql_query ($query); // Add more detailed error reporting, if desired. } } else { // If the query did not run OK. echo '<p><font color="red">Your submission could not be processed due to a system error. We apologize for any inconvenience.</font></p>'; // Print the query and invoke the mysql_error() function to debug. } } // End of if (isset($the_file)... } // End of FOR loop. mysql_close(); // Close the database connection. } // End of the main Submit conditional. ?> <form enctype="multipart/form-data" action="add_file_thankyou.php" method="post"> <fieldset><legend>Fill out the form to upload a file:</legend> <input type="hidden" name="MAX_FILE_SIZE" value="524288"> <?php // Create the inputs. for ($i = 0; $i < $counter; $i++) { echo '<p><b>First Name:</b> <input type="text" name="firstname' . $i . '" size="20"</p> <p><b>Last name:</b> <input type="text" name="lastname' . $i . '" size="20"></p> <p><b>Email Address:</b> <input type="text" name="email' . $i . '" size="20"></p> <p><b>Nationality:</b> <input type="text" name="citizenship' . $i . '" size="20"></p> <p><b>Your Current Location:</b> <input type="text" name="location' . $i . '" size="20"></p> <p><b>Upload Your CV:</b> <input type="file" name="upload' . $i . '" /></p> '; } ?> </fieldset> <input type="hidden" name="submitted" value="TRUE" /> <div align="center"><input type="submit" name="submit" value="Submit" /></div> </form> <?php include ('./includes/footer.html'); ?>
  2. Thanks Larry for your reply. I would do that, but I honestly don't know how I would modify the code to suit the new server. Should I copy the script here if you have a sec to look at it?
  3. I have created a database using the script that sends the file to a folder I named /uploads. I now have 20,000 uploads to my database, all running fine. I have opened a new domain on a different server and have uploaded the scripts and have created new MySQL databases and have uploaded the /uploads file with all the associated files to the new server. All runs properly except when downloading the file. The link is correctly associated to the correct file numbered accordingly and it does start to open, but the files are not opening properly due to that the server I downloaded them from to then upload to my server has a different path name according to tech support on the new server. Is there a way to download the /uploads folder to my local drive then upload this file to my new server without the path name that the server reads changing?
×
×
  • Create New...