I know this might not be what you want, but try this. Call the functions.php
file within the add_provider_logic.php
file.
<?php
//echo 'FILES["Image"]<pre>';
//print_r($_FILES['Image']);
//echo '</pre>';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
require('functions.php'); // Require the functions.php file
$name = testInput($_POST['Name']);
$email = testInput($_POST['Email']);
$phone1 = testInput($_POST['phone1']);
$phone2 = testInput($_POST['phone2']);
$phone3 = testInput($_POST['phone3']);
$id = testInput($_POST['userID']);
$method = testInput($_POST['Method']);
$rate = testInput($_POST['Rate']);
$weight = testInput($_POST['Weight']);
$h_feet = testInput($_POST['HFeet']);
$h_inches = testInput($_POST['HInches']);
$waist = testInput($_POST['Waist']);
$cup = testInput($_POST['Cup']);
$age = testInput($_POST['Age']);
$ethnicity = testInput($_POST['Ethnicity']);
$introduction= testInput($_POST['Introduction']);
$thumb = testInput($_FILES['Thumb']['name']);
$phone = $phone1.$phone2.$phone3;
$ip = getRealIpAddr();
$sql = "INSERT INTO providers
(userID,name,email,phone,cMethod,rate,weight,hFeet,hInches,waist,cup,ethnicity,age,introduction,thumb,ip)
VALUES
(:id,:name,:email,:phone,:method,:rate,:weight,:hFeet,:hInches,:waist,:cup,:ethnicity,:age,:intro,:thumb,:ip)"; // SQL Statement
$prepare = $conn->prepare($sql); // Prepare the SQL Statement
// Create an array of named parameters to bind and execute
$parameters = array(
':id' => $id,
':method' => $method,
':rate' => $rate,
':weight' => $weight,
':name' => $name,
':email' => $email,
':phone' => $phone,
':waist' => $waist,
':hFeet' => $h_feet,
':hInches' => $h_inches,
':age' => $age,
':cup' => $cup,
':intro' => $introduction,
':ethnicity' => $ethnicity,
':thumb' => $thumb,
':ip' => $ip,
);
if($prepare->execute($parameters)) {
$providerID = $conn->lastInsertId();
$upload_directory = 'images/providers/'.$providerID;
mkdir($upload_directory);
mkdir($upload_directory."/del");
$sql = "UPDATE users SET providerID = :providerID WHERE id = :id"; // SQL Statement
$prepare = $conn->prepare($sql); // Prepare the SQL Statement
// Create an array of named parameters to bind and execute
$parameters = array(
':providerID' => $providerID,
':id' => $id,
);
if($prepare->execute($parameters)) {
//echo "users table updated, providerID = .".$providerID." for user ".$id;
$total = count($_POST['Options']);
for($i = 0; $i < $total; $i++) {
$sql = "INSERT INTO providers_options (optionName, providerID) VALUES (:option,:providerID)"; // SQL Statement
$prepare = $conn->prepare($sql); // Prepare the SQL Statement
// Create an array of named parameters to bind and execute
$parameters = array(
':providerID' => $providerID,
':option' => $_POST['Options'][$i],
);
$prepare->execute($parameters);
}
}
} else {
header('Location: provider_exists.php');
die();
}
//upload featured pic
if(isset($thumb)) {
if($thumb != '') {
//echo 'Upload Diectory: '.$upload_directory;
$tmp = $_FILES['Thumb']['tmp_name']; // Create and ppend a variable to tmp_name
$image = $thumb; // Create and append a variable to tmp_name
require('test_image.php');
//echo '<br>Featured Pic: '.$tmp.' => '.$file;
move_uploaded_file($tmp, $file);
}
}
//upload pictures
if(isset($_FILES['Image']['name'][0])) {
if($_FILES['Image']['name'][0] != '') {
$total = count($_FILES['Image']['name']);
//echo '<pre>';print_r($_FILES['Image']);echo '</pre>';
//echo '<br>Count of Images: '.$total.', to be uploaded!<br>';
// Loop through each file
for($i = 0; $i < $total; $i++) {
$tmp = $_FILES['Image']['tmp_name'][$i]; // Create and ppend a variable to tmp_name
$image = $_FILES['Image']['name'][$i]; // Create and append a variable to tmp_name
require('test_image.php');
//echo '<br>Image '.$i.': '.$tmp.' => '.$file;
move_uploaded_file($tmp, $file);
}
}
} // do nothing if the first image isn't selected (meaning no image is selected)
$_SESSION['add_provider'] = '0';
$_SESSION['providerID'] = $providerID;
//echo "<br>Provider: ".$providerID;
//echo '<br>User: '.$id;
require('success.php');
}
?>
I am not entirely sure why it’s acting this way when mine works without the need to put it directly within the add_provider_logic.php
file.
Actually, try putting the functions.php
file at the top/ outside of the if
statements.