Hi,
I am looking for some help with my script, since only half of it is working. The image path will not be put in the database for some reason and when I process the form all I get is white space:
$reg_errors = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ((isset($_GET['packageID'])) && (is_numeric($_GET['package_ID']))) {
$packageID = (int) $_GET['packageID'];
} elseif ((isset($_POST['packageID'])) && (is_numeric($_POST['packageID']))) {
$packageID = (int) $_POST['packageID'];
} else {
echo 'Sorry No Package ID';
include ('../includes/footer.php');
exit();
}
if (preg_match ('/^[A-Z \'.-]{2,100}$/i', $_POST['companyname'])) {
$companyName = mysqli_real_escape_string ($dbc, strip_tags($_POST
['companyname']));
} else {
$reg_errors['companyname'] = 'Enter Your Company Name';
}
$companyWebsite = mysqli_real_escape_string ($dbc, strip_tags($_POST['companywebsite']));
if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $_POST['companyemail'])) {
$companyEmail = mysqli_real_escape_string ($dbc, strip_tags($_POST['companyemail']));
} else {
$reg_errors['companyemail'] = 'Enter A Valid Company Email Address';
}
if (filter_var($_POST['CountryCode'], FILTER_SANITIZE_STRING)) {
$companyLocation = mysqli_real_escape_string ($dbc, $_POST['CountryCode']);
} else {
$reg_errors['CountryCode'] = 'Select Your Companies Location';
}
if (isset($_FILES['new_image'])) {
$imagename = $_FILES['new_image']['name'];
$source = $_FILES['new_image']['tmp_name'];
$target = "../pictures/".$imagename;
move_uploaded_file($source, $target);
$imagepath = $imagename;
$save = "../pictures/logos/" . $imagepath;
$file = "../pictures/" . $imagepath;
list($width, $height) = getimagesize($file);
$modwidth = 150;
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight);
$image = imagecreatefromjpeg($file);
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
imagejpeg($tn, $save, 100);
$newLogo = $_FILES['new_image']['name'];
}
if (empty($reg_errors)) { // if everythings okay
$q = "INSERT INTO Company(CompanyName,CompanyWebsite,CompanyEmail,CountryCode)VALUES('$companyName','$companyWebsite','$companyEmail','$companyLocation')";
$r = mysqli_query($dbc, $q);
if(mysqli_affected_rows($dbc) == 1) {
$companyID = mysqli_insert_id($dbc);
$_SESSION['companyID'] = $companyID;
$q = "INSERT INTO pictures (CompanyID,logoPath) VALUES ({$_SESSION['companyID']},$newLogo)";
$r = mysqli_query($dbc, $q);
if(mysqli_affected_rows($dbc) == 1) {
echo 'Test Worked';
} else {
echo 'problem with image upload';
}
} else {
echo 'problem with company insert';
}
} // End Errors Condition
echo '<span class="errorMSG">' . $errors[$name] . '</span>';
} // End Main Conditional Operator
?>
Again any help would be much appreciated, it's the image part of the script that is not working properly as if I just run the company query then that will work fine.
Thanks