Need help to combine 2 PHP scripts into 1 script

Ok so I have two scripts to insert data into MySQL, 1 of them only inserts text, the other uploads an image to a folder and stores the path in MySQL. I need to join them together so that I can incorporate the 1 into my forms that require an image along with text be inserted to MySQL.

Here is the text only code:


Untitled 2 <?php


mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name")or die(“cannot select DB”);

// Get values from form

// Insert data into mysql
$sql=“INSERT INTO $tbl_name(part_description, part_number, model_number, serial_number, item_color, manufacture, quantity, cost, condition, availability, reason, comments, warranty_date, purchase_date, location,) VALUES(’$part_description’, ‘$part_number’, ‘$model_number’, ‘$serial_number’,’$item_color’,’$manufacture’,’$quantity’,’$cost’,’$condition’,’$availability’,’$reason’,’$comments’,’$warranty_date’,’$purchase_date’,’$location’)”;

// if successfully insert data into database, displays message “Successful”.
echo “Successful”;
echo “

echo “Back to main page”;

else {
echo “ERROR”;

// close connection


And here is the code that uploads an image to a folder and stores the path in MySQL:

// After the form loads, if the submit button is pressed
if (isset ($_POST[‘submit’]))
$errors=array(); //declaration of an array which we will us to display erros

$image=$_FILES[‘image’][‘name’];// taking the file name and storing in variable
$file_tmp=$_FILES[‘image’][‘tmp_name’];// this is a temporary variable

// now if the image name is empty…
if (empty($image))
$errors[]=“Please Enter All Fields”;// showing the error as an array
if (empty($errors))// now if the error array is empty this means we have no errors and all things are ok


// Here is where we upload a copy of the image to our folder ‘uploads/images/’
move_uploaded_file ($file_tmp, ‘uploads/images/’.$image);

//now we show the errors in a foreach loop, if no errros then ‘Upload Completed Successfully’ should display in GREEN!
$errors[]=“Upload Completed Successfully!”;
foreach ($errors as $err)
echo “$err”;

Sponsor our Newsletter | Privacy Policy | Terms of Service