upload/insert blob problem

Alles, was PHP betrifft, kann hier besprochen werden.

upload/insert blob problem

Postby lunaticbit » 11. June 2015 11:12

I' m facing problems when I try to insert rows in a table with a BLOB column.
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!
lunaticbit
 
Posts: 21
Joined: 09. April 2015 16:24
Operating System: Windows 7

Re: upload/insert blob problem

Postby Nobbie » 11. June 2015 12:57

lunaticbit wrote:Is amy problem mixing literals with file manipulation in the same <form> ??


No, you simply forgot an "S", because it is $_FILES and not $_FILE.

http://php.net/manual/en/features.file- ... method.php
Nobbie
 
Posts: 8779
Joined: 09. March 2008 13:04

Re: upload/insert blob problem

Postby lunaticbit » 14. June 2015 16:31

Don't know from qhat thos ovvious error has dericed, snce there' s nuch thing in thw module,
so thanksfor you time so far, preparing to ask much more seirous yhings as:

Warning: mysql_query(): MySQL server has gone away in C:\xampp\htdocs\nic\insert_form.php on line 63

Warning: mysql_query(): Error reading result set's header in C:\xampp\htdocs\nic\insert_form.php on line 63

where line 63 states:
mysql_query($qry) or die("<h1>Error... Query Failed!</h1>");

bye bye for the time being!
lunaticbit
 
Posts: 21
Joined: 09. April 2015 16:24
Operating System: Windows 7

Re: upload/insert blob problem

Postby Nobbie » 14. June 2015 19:02

We have no source code for insert_form.php

But what immediately comes to mind, you obviously have a horrible mix of mysqli classes and mysqli functions and mysql functions - that is a pain and wont work ever. I already told you, that this forum is NOT mentioned for teaching PHP. You have to learn and to exercise the basics on yourself.
Nobbie
 
Posts: 8779
Joined: 09. March 2008 13:04

Re: upload/insert blob problem

Postby lunaticbit » 12. January 2016 09:47

I understand that, but some highlights to lead to the appropriate stuff for further searching would be fine
lunaticbit
 
Posts: 21
Joined: 09. April 2015 16:24
Operating System: Windows 7

Re: upload/insert blob problem

Postby Nobbie » 12. January 2016 13:58

lunaticbit wrote:but some highlights to lead to the appropriate stuff for further searching would be fine


The PHP manual is the perfect "highlight" for all questions about PHP: http://php.net/manual
Nobbie
 
Posts: 8779
Joined: 09. March 2008 13:04


Return to PHP

Who is online

Users browsing this forum: No registered users and 2 guests