In fact I'm trying to insrt a file (content, mime, size, data) and some extra columns concerning user & timp.
So on page A(select.php) the cose is:
- Code: Select all
[
<html>
<head>
<style>
@import url("megla/nic.css");
</style>
</head>
<body>
<h1>select</h1>
<hr color = "magenta">
<?php
$l_name = $_REQUEST['x_name'];
echo "<h3Dear, $l_name , select a file to upload/insert in the DB...</h3>";
echo "<form action=\"insert.php\" method=\"post\" enctype=\"multipart/form-data\">";
echo "<table align=\"center\" width = \"50%\">";
echo "<tr align = \"center\">";
echo "<th align = \"center\"> select file</th>";
echo "<td><input type=\"file\" name=\"datafile\" size=\"50\"</td>";
echo "</tr>";
echo "<tr align = \"center\">";
echo "<th align = \"center\">comment</th>";
echo "<td><input type=\"text\" name=\"comment\" size=\"60\" value=\"\"</td>";
echo "</tr>";
echo "<tr align = \"center\">";
echo "<td><br><br></td>";
echo "<td><input type=\"submit\" name=\"submit\" value=\"Submit\"></td>";
echo "</tr>";
echo "</table>";
echo "<input type=\"hidden\" name=\"my_user\" value=\"$l_name\">";
echo "</form>";
//echo ("<p align =\"center\">");
//echo ("<textarea name=\"comment\" form=\"nicform\">Enter comments text here...</textarea>");
//echo ("</p>");
?>
</body>
</html>
/code]
The module that has to complete the task Page B (insert.php) contains:
[code][/code]
<html>
<head>
<style>
@import url("megla/nic.css");
</style>
</head>
<body>
<h1>insert</h1>
<hr color = "magenta">
<p align = "center">
<?php
//db connection//
$conn = mysqli_connect("localhost","root","","test");
if (mysqli_connect_errno())
{
echo "<p style=\"color:red\" style=\"font-size:20px\" align = \"center\" text-color = \"red\">";
echo "Failed to connect to MySQL: " . mysqli_connect_error();
echo "<image src = \"droopy.png\">";
echo "</p>";
}
else
{
echo "<p style=\"color:green\" style=\"font-size:20px\" align = \"center\" color = \"green\">";
echo "Successfully connected to MySQL! ";
echo "<image src = \"fethry.png\">";
echo "</p>";
}
$user = $_REQUEST['my_user'];
$name = $_REQUEST['datafile'];
$comment = $_REQUEST['comment'];
$type = $_FILE['datafile']['type'];
//..............................................................
echo ("<li>user: $user <br><br>");
echo ("<li>name: $name <br><br>");
echo ("<li>comment: $comment <br><br>");
//$conn = mysqli_connect("localhost","root","","test");
/*
$result = $mysqli->query("INSERT INTO arxeio
( name, type, size, data, date, user)
VALUES
('$name', '$type', $size, '$data', now(), '$user')
)";
if($result)
{
echo "Record Inserted!";
}
else
{
echo "Record Failed to Insert";
}
*/
mysqli_close($conn);
?>
</p>
<hr color = "magenta">
</body>
</html>
]
As you can see I omitted the INSERT statements, untill the problem returns no errors.
The message prompts:
Notice: Undefined variable: _FILE in C:\xampp\htdocs\myfolder\insert.php on line ... *** $type = $_FILE['datafile']['type']; *** or any other #_FILES clausem(name, size, temp_name)
Is amy problem mixing literals with file manipulation in the same <form> ??
Thnx in advance!