Hi!
I have a problem... I need to make simple upload script which for me as a novice php programmer isnt so simple aat aall! So if someone could point me to a good tutorial or solve my problem, it would be great!
Ok, this is what i have now. Please dont laugh hahaha
<?php include ('head.php') ?>
<?php
$con = mysql_connect("localhost","root","*");
if (!$con)
{
die('Could not connect to the database: ' . mysql_error());
}
mysql_select_db("warehousemanagement", $con);
$sql="INSERT INTO parts (username, customer_name, customer_address, date, warehouse, part_number, description, serial_number, quantity, part_condition, certificate_number, certificate_date, location, incoming_reference, shelf_life_end_date, dangerous_goods)
VALUES
('$_POST[username]','$_POST[customer_name]','$_POST[customer_address]','$_POST[date]','$_POST[warehouse]','$_POST[part_number]','$_POST[description]','$_POST[serial_number]','$_POST[quantity]','$_POST[part_condition]','$_POST[certificate_number]','$_POST[certificate_date]','$_POST[location]','$_POST[incoming_reference]','$_POST[shelf_life_end_date]','$_POST[dangerous_goods]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
echo "<br />";
echo "<a href='admin/insert-records.php'>Add another record</a>";
?>
<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$con = mysql_connect("localhost","root","*");
if (!$con)
{
die('Could not connect to the database: ' . mysql_error());
}
mysql_select_db("warehousemanagement", $con);
$query = "INSERT INTO parts (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
mysql_close($con);
echo "<br>File $fileName uploaded<br>";
}
mysql_close($con);
?>
<?php include ('footer.php') ?>
This kinda works, but it inserts it in two sepparate rows... Can someone please avise what to do?
Thank you!