I have these two scripts. One is an mysql INSERT INTO
a DATABASE
.
The second created a new directory and uploads upto 5 images into the newly created folder.
They both work as seperate entities but when i try and combine them it will not insert the information into the database. There must be something conflicting that I just cant see.
Here is the upload files code that works:
<?php
// Assigning $_POSTS to variables
//login details
$username_entry = $_POST['username_entry'];
$password_entry = $_POST['password_entry'];
//!login details
//contact details
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$tel = $_POST['tel'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$address3 = $_POST['address3'];
$address4 = $_POST['address4'];
$postcode = $_POST['postcode'];
$facebook = $_POST['facebook'];
$twitter = $_POST['twitter'];
$whatareyou = $_POST['whatareyou'];
$business_description = $_POST['business_description'];
$website = $_POST['website'];
//!contact details
//opening times
$opening_monday_from = $_POST ['opening_monday_from'];
$opening_monday_to = $_POST ['opening_monday_to'];
$opening_tuesday_from = $_POST ['opening_tuesday_from'];
$opening_tuesday_to = $_POST ['opening_tuesday_to'];
$opening_wednesday_from = $_POST ['opening_wednesday_from'];
$opening_wednesday_to = $_POST ['opening_wednesday_to'];
$opening_thursday_from = $_POST ['opening_thursday_from'];
$opening_thursday_to = $_POST ['opening_thursday_to'];
$opening_friday_from = $_POST ['opening_friday_from'];
$opening_friday_to = $_POST ['opening_friday_to'];
$opening_saturday_from = $_POST ['opening_saturday_from'];
$opening_saturday_to = $_POST ['opening_saturday_to'];
$opening_sunday_from = $_POST ['opening_sunday_from'];
$opening_sunday_to = $_POST ['opening_sunday_to'];
//!opening times
// !Assigning $_POSTS to varaiables
// DataBase credentials
$user = 'root';
$password = 'root';
$db = 'welcometowarwick';
$host = 'localhost';
$port = 8889;
//! DataBase credentials
// Connect to DataBase
$link = mysqli_init();
$success = mysqli_real_connect(
$link,
$host,
$user,
$password,
$db,
$port
);
//! Connect to DataBase
$directoryPath = "user_images/".$username_entry;
mkdir($directoryPath, 0777, true);
if (isset($_FILES['upload']) === true) {
$files = $_FILES['upload'];
for($x = 0; $x < count($files['name']); $x++) {
$name = $files['name'][$x];
$tmp_name = $files['tmp_name'][$x];
move_uploaded_file($tmp_name, "user_images/{$username_entry}/{$name}");
//echo '<pre>', print_r($files['name'][0], true), '</pre>';
$image_upload1 = ($files['name'][0]);
$image_upload2 = ($files['name'][1]);
$image_upload3 = ($files['name'][2]);
$image_upload4 = ($files['name'][3]);
$image_upload5 = ($files['name'][4]);
}
$insert_upload1 = "user_images/$username_entry/$image_upload1";
$insert_upload2 = "user_images/$username_entry/$image_upload2";
$insert_upload3 = "user_images/$username_entry/$image_upload3";
$insert_upload4 = "user_images/$username_entry/$image_upload4";
$insert_upload5 = "user_images/$username_entry/$image_upload5";
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
$insertSQL = sprintf("INSERT INTO ofnissenisub321 (timestamp, username, password, business_name, address1, address2, address3, postcode, email, website, Facebook, twitter, linkedin, opening_monday_from, opening_monday_to, opening_tuesday_from, opening_tuesday_to, opening_wednesday_from, opening_wednesday_to, opening_thursday_from, opening_friday_from, opening_friday_to, opening_saturday_from, opening_saturday_from, opening_saturday_to, opening_sunday_from, opening_sunday_to, business_type, business_description, managers_message, image_1, image_2, image_3, image_4, image_5) VALUES (NOW(), %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['username_entry'], "text"),
GetSQLValueString($_POST['password_entry'], "text"),
GetSQLValueString($_POST['business_name'], "text"),
GetSQLValueString($_POST['address1'], "text"),
GetSQLValueString($_POST['address2'], "text"),
GetSQLValueString($_POST['address3'], "text"),
GetSQLValueString($_POST['postcode'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['website'], "text"),
GetSQLValueString($_POST['facebook'], "text"),
GetSQLValueString($_POST['twitter'], "text"),
GetSQLValueString($_POST['linkedin'], "text"),
GetSQLValueString($_POST['opening_monday_from'], "text"),
GetSQLValueString($_POST['opening_monday_to'], "text"),
GetSQLValueString($_POST['opening_tuesday_from'], "text"),
GetSQLValueString($_POST['opening_tuesday_to'], "text"),
GetSQLValueString($_POST['opening_wednesday_from'], "text"),
GetSQLValueString($_POST['opening_wednesday_to'], "text"),
GetSQLValueString($_POST['opening_thursday_from'], "text"),
GetSQLValueString($_POST['opening_thursday_to'], "text"),
GetSQLValueString($_POST['opening_friday_from'], "text"),
GetSQLValueString($_POST['opening_friday_to'], "text"),
GetSQLValueString($_POST['opening_saturday_from'], "text"),
GetSQLValueString($_POST['opening_saturday_to'], "text"),
GetSQLValueString($_POST['opening_sunday_from'], "text"),
GetSQLValueString($_POST['opening_sunday_to'], "text"),
GetSQLValueString($_POST['business_type'], "text"),
GetSQLValueString($_POST['business_description'], "text"),
GetSQLValueString($_POST['managers_message'], "text"),
GetSQLValueString($insert_upload1, "text"),
GetSQLValueString($insert_upload2, "text"),
GetSQLValueString($insert_upload3, "text"),
GetSQLValueString($insert_upload4, "text"),
GetSQLValueString($insert_upload5, "text"));
mysql_select_db($database_w2w, $w2w);
$Result1 = mysql_query($insertSQL, $w2w) or die(mysql_error()); }
if (mysqli_query($link, $sql)) {
echo "New record created successfully $username_entry";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($link);
}
mysqli_close($link);
//! MySQLi insertInto
?>
?>
And here is the INSERT code, again, works:
<?php
// Assigning $_POSTS to variables
//login details
$username_entry = $_POST['username_entry'];
$password_entry = $_POST['password_entry'];
//!login details
//contact details
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$tel = $_POST['tel'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$address3 = $_POST['address3'];
$address4 = $_POST['address4'];
$postcode = $_POST['postcode'];
$facebook = $_POST['facebook'];
$twitter = $_POST['twitter'];
$whatareyou = $_POST['whatareyou'];
$business_description = $_POST['business_description'];
$website = $_POST['website'];
//!contact details
//opening times
$opening_monday_from = $_POST ['opening_monday_from'];
$opening_monday_to = $_POST ['opening_monday_to'];
$opening_tuesday_from = $_POST ['opening_tuesday_from'];
$opening_tuesday_to = $_POST ['opening_tuesday_to'];
$opening_wednesday_from = $_POST ['opening_wednesday_from'];
$opening_wednesday_to = $_POST ['opening_wednesday_to'];
$opening_thursday_from = $_POST ['opening_thursday_from'];
$opening_thursday_to = $_POST ['opening_thursday_to'];
$opening_friday_from = $_POST ['opening_friday_from'];
$opening_friday_to = $_POST ['opening_friday_to'];
$opening_saturday_from = $_POST ['opening_saturday_from'];
$opening_saturday_to = $_POST ['opening_saturday_to'];
$opening_sunday_from = $_POST ['opening_sunday_from'];
$opening_sunday_to = $_POST ['opening_sunday_to'];
//!opening times
// !Assigning $_POSTS to varaiables
// DataBase credentials
$user = 'root';
$password = 'root';
$db = 'welcometowarwick';
$host = 'localhost';
$port = 8889;
//! DataBase credentials
// Connect to DataBase
$link = mysqli_init();
$success = mysqli_real_connect(
$link,
$host,
$user,
$password,
$db,
$port
);
//! Connect to DataBase
//MySQLi insertInto
$sql = "INSERT INTO business_info
(
username,
password,
email,
email2,
tel,
address1,
address2,
address3,
address4,
postcode,
facebook,
twitter,
opening_monday_to,
opening_monday_from,
opening_tuesday_to,
opening_tuesday_from,
opening_wednesday_to,
opening_wednesday_from,
opening_thursday_to,
opening_thursday_from,
opening_friday_to,
opening_friday_from,
opening_saturday_to,
opening_saturday_from,
opening_sunday_to,
opening_sunday_from,
whatareyou,
business_description,
image1,
image2,
image3,
image4,
image5,
website
)
VALUES
(
'$username_entry',
'$password_entry',
'$email1',
'$email2',
'$tel',
'$address1',
'$address2',
'$address3',
'$address4',
'$postcode',
'$facebook',
'$twitter',
'$opening_monday_to',
'$opening_monday_from',
'$opening_tuesday_to',
'$opening_tuesday_from',
'$opening_wednesday_to',
'$opening_wednesday_from',
'$opening_thursday_to',
'$opening_thursday_from',
'$opening_friday_to',
'$opening_friday_from',
'$opening_saturday_to',
'$opening_saturday_from',
'$opening_sunday_to',
'$opening_sunday_from',
'$whatareyou',
'$business_description',
'$image1',
'$image2',
'$image3',
'$image4',
'$image5',
'$website'
)";
if (mysqli_query($link, $sql)) {
echo "New record created successfully $username_entry";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($link);
}
mysqli_close($link);
//! MySQLi insertInto
?>
I have tried different combinations of these two codes (which is why there are irrelevent bits in the UPLOAD
script. However both just tested seperately and both do the jobs required. I just cant get them to both run at the same time.
Can anyone shed some light on this please. Thanks :)
Basically I just want to add the mkdir upload script into the INSERT
script without disrupting it....
******EDIT HERE IS THE SCRIPT I CANNOT MAKE WORK******
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Assigning $_POSTS to variables
//login details
$username_entry = $_POST['username_entry'];
$password_entry = $_POST['password_entry'];
//!login details
//contact details
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$tel = $_POST['tel'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$address3 = $_POST['address3'];
$address4 = $_POST['address4'];
$postcode = $_POST['postcode'];
$facebook = $_POST['facebook'];
$twitter = $_POST['twitter'];
$whatareyou = $_POST['whatareyou'];
$business_description = $_POST['business_description'];
$website = $_POST['website'];
//!contact details
//opening times
$opening_monday_from = $_POST ['opening_monday_from'];
$opening_monday_to = $_POST ['opening_monday_to'];
$opening_tuesday_from = $_POST ['opening_tuesday_from'];
$opening_tuesday_to = $_POST ['opening_tuesday_to'];
$opening_wednesday_from = $_POST ['opening_wednesday_from'];
$opening_wednesday_to = $_POST ['opening_wednesday_to'];
$opening_thursday_from = $_POST ['opening_thursday_from'];
$opening_thursday_to = $_POST ['opening_thursday_to'];
$opening_friday_from = $_POST ['opening_friday_from'];
$opening_friday_to = $_POST ['opening_friday_to'];
$opening_saturday_from = $_POST ['opening_saturday_from'];
$opening_saturday_to = $_POST ['opening_saturday_to'];
$opening_sunday_from = $_POST ['opening_sunday_from'];
$opening_sunday_to = $_POST ['opening_sunday_to'];
//!opening times
// !Assigning $_POSTS to varaiables
// DataBase credentials
$user = 'root';
$password = 'root';
$db = 'welcometowarwick';
$host = 'localhost';
$port = 8889;
//! DataBase credentials
// Connect to DataBase
$link = mysqli_init();
$success = mysqli_real_connect(
$link,
$host,
$user,
$password,
$db,
$port
);
//! Connect to DataBase
$directoryPath = "user_images/".$username_entry;
mkdir($directoryPath, 0777, true);
if (isset($_FILES['upload']) === true) {
$files = $_FILES['upload'];
for($x = 0; $x < count($files['name']); $x++) {
$name = $files['name'][$x];
$tmp_name = $files['tmp_name'][$x];
move_uploaded_file($tmp_name, "user_images/{$username_entry}/{$name}");
//echo '<pre>', print_r($files['name'][0], true), '</pre>';
$image_upload1 = ($files['name'][0]);
$image_upload2 = ($files['name'][1]);
$image_upload3 = ($files['name'][2]);
$image_upload4 = ($files['name'][3]);
$image_upload5 = ($files['name'][4]);
}
$insert_upload1 = "user_images/$username_entry/$image_upload1";
$insert_upload2 = "user_images/$username_entry/$image_upload2";
$insert_upload3 = "user_images/$username_entry/$image_upload3";
$insert_upload4 = "user_images/$username_entry/$image_upload4";
$insert_upload5 = "user_images/$username_entry/$image_upload5";
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
$insertSQL = sprintf("INSERT INTO ofnissenisub321 (timestamp, username, password, business_name, address1, address2, address3, postcode, email, website, Facebook, twitter, linkedin, opening_monday_from, opening_monday_to, opening_tuesday_from, opening_tuesday_to, opening_wednesday_from, opening_wednesday_to, opening_thursday_from, opening_friday_from, opening_friday_to, opening_saturday_from, opening_saturday_from, opening_saturday_to, opening_sunday_from, opening_sunday_to, business_type, business_description, managers_message, image_1, image_2, image_3, image_4, image_5) VALUES (NOW(), %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['username_entry'], "text"),
GetSQLValueString($_POST['password_entry'], "text"),
GetSQLValueString($_POST['business_name'], "text"),
GetSQLValueString($_POST['address1'], "text"),
GetSQLValueString($_POST['address2'], "text"),
GetSQLValueString($_POST['address3'], "text"),
GetSQLValueString($_POST['postcode'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['website'], "text"),
GetSQLValueString($_POST['facebook'], "text"),
GetSQLValueString($_POST['twitter'], "text"),
GetSQLValueString($_POST['linkedin'], "text"),
GetSQLValueString($_POST['opening_monday_from'], "text"),
GetSQLValueString($_POST['opening_monday_to'], "text"),
GetSQLValueString($_POST['opening_tuesday_from'], "text"),
GetSQLValueString($_POST['opening_tuesday_to'], "text"),
GetSQLValueString($_POST['opening_wednesday_from'], "text"),
GetSQLValueString($_POST['opening_wednesday_to'], "text"),
GetSQLValueString($_POST['opening_thursday_from'], "text"),
GetSQLValueString($_POST['opening_thursday_to'], "text"),
GetSQLValueString($_POST['opening_friday_from'], "text"),
GetSQLValueString($_POST['opening_friday_to'], "text"),
GetSQLValueString($_POST['opening_saturday_from'], "text"),
GetSQLValueString($_POST['opening_saturday_to'], "text"),
GetSQLValueString($_POST['opening_sunday_from'], "text"),
GetSQLValueString($_POST['opening_sunday_to'], "text"),
GetSQLValueString($_POST['business_type'], "text"),
GetSQLValueString($_POST['business_description'], "text"),
GetSQLValueString($_POST['managers_message'], "text"),
GetSQLValueString($insert_upload1, "text"),
GetSQLValueString($insert_upload2, "text"),
GetSQLValueString($insert_upload3, "text"),
GetSQLValueString($insert_upload4, "text"),
GetSQLValueString($insert_upload5, "text"));
mysql_select_db($success, $insertSQL);
$Result1 = mysql_query($insertSQL, $link) or die(mysql_error()); }
if (mysqli_query($link, $sql)) {
echo "New record created successfully $username_entry";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($link);
}
mysqli_close($link);
//! MySQLi insertInto
?>
?>