Hi everyone,
I will very quickly explain what im doing. I have a 2 files called addcustomer.php & fileupload.php
Two tables called customers & images
Im new to php and I got a script for helping to upload images into a database table called images. This works fine on its own. The only problem I have is that I need to add the customerID with the INSERT command into the sql query. ( i think ! )
This is the table that the customerID and image details are going to .
CREATE TABLE `image` (
`image_id` int(10) unsigned NOT NULL auto_increment,
`customerID` tinyint(11) NOT NULL default '0',
`image_type` varchar(50) NOT NULL default '',
`image` longblob NOT NULL,
`image_size` bigint(20) NOT NULL default '0',
`image_name` varchar(255) NOT NULL default '',
`image_date` datetime NOT NULL default '0000-00-00 00:00:00',
UNIQUE KEY `image_id` (`image_id`)
) TYPE=MyISAM ;
The page addcustomer.php is passing the companyName to fileupload.php
Once I have this i can then get the customerID from the database.
The only help I need is getting the customerID into the database
Any ideas would be great, also if you think im doing anything wrong please mention also.
Thanks in advance , pecobrown
Fileupload.php
<?php
// database connection
$conn = mysql_connect("localhost", "username", "password") OR DIE (mysql_error());
@mysql_select_db ("mydatabase", $conn) OR DIE (mysql_error());
//carry over companyName from previous page and then get customerID from the database
$companyName = $_POST['companyName'];
$sql = mysql_query("SELECT customerID FROM tblcustomers WHERE companyName = '$companyName' ");
$getid = mysql_fetch_array($sql);
$customerID = $getid['customerID'];
// Do this process if user has browse the file and click the submit button to add image
if ($_FILES) {
$image_types = Array ("image/bmp",
"image/jpeg",
"image/pjpeg",
"image/gif",
"image/x-png");
$userfile = addslashes (fread (fopen ($_FILES["userfile"] ["tmp_name"], "r"), filesize ($_FILES["userfile"]["tmp_name"])));
$file_name = $_FILES["userfile"]["name"];
$file_size = $_FILES["userfile"]["size"];
$file_type = $_FILES["userfile"]["type"];
// this will add image details ,but also customerID at the same time
if (in_array (strtolower ($file_type), $image_types)) {
$sql = "INSERT INTO image (image_type, image, image_size, image_name, image_date) ";
$sql.= "VALUES (";
$sql.= "'{$file_type}', '{$userfile}', '{$file_size}', '{$file_name}', NOW())";
@mysql_query ($sql, $conn);
Header("Location:".$_SERVER["PHP_SELF"]);
exit();
}
}
?>
<html>
<head>
<title>Storing Images in DB with customerID</title>
<link href="./assets/css/wplanner.css" rel="stylesheet" type="text/css">
</head>
<body class="smalltextlink">
<form method="post" enctype="multipart/form-data">
<span class="smalltext">Select Image File:</span>
<input type="file" name="userfile" size="40"><input type="submit" value="submit">
</form>
</body>
</html>
// Example PHP Script, demonstrating Storing Image in Database
// Detailed Information can be found at
http://www.codewalkers.com