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:

[php]

Untitled 2 <?php

$host=“localhost”;
$username=“root”;
$password=“xxxxx”;
$db_name=“portal”;
$tbl_name=“inventory”;

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

// Get values from form
$part_description=$_POST[‘part_description’];
$part_number=$_POST[‘part_number’];
$model_number=$_POST[‘model_number’];
$serial_number=$_POST[‘serial_number’];
$item_color=$_POST[‘item_color’];
$manufacture=$_POST[‘manufacture’];
$quantity=$_POST[‘quantity’];
$cost=$_POST[‘cost’];
$condition=$_POST[‘condition’];
$availability=$_POST[‘availability’];
$reason=$_POST[‘reason’];
$comments=$_POST[‘comments’];
$warranty_date=$_POST[‘warranty_date’];
$purchase_date=$_POST[‘purchase_date’];
$location=$_POST[‘location’];

// 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’)”;
$result=mysql_query($sql);

// if successfully insert data into database, displays message “Successful”.
if($result){
echo “Successful”;
echo “
”;

echo “Back to main page”;
}

else {
echo “ERROR”;
}

// close connection
mysql_close();
?>

[/php]

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

[php]<?php
// 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!”;
}
else
{
foreach ($errors as $err)
{
echo “$err”;
}
}
}
?>
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service