0

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!

3
Contributors
4
Replies
7
Views
4 Years
Discussion Span
Last Post by dbalas
0

You have two insert queries, so yes, you'll get two rows. Was that the problem? Were you thinking of one select or update?

0

Hi!

The problem is that i cant make one single query to insert everything. I know it is easy for someone that knows php but for me its hard :) I found files insert tutorial on the web but i dont know how to rewrite it to make it possible to add some text and date fields ...

0

You need to merge lines 12-14 and 53,54. If you move the first query to the position of the second, you just need to add the 4 column names and values into the first query:

$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, name, size, type, content)
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]', '$fileName', '$fileSize', '$fileType', '$content')";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.