Im having trouble on updating the file inside mysql database using the php. Should I use <form> or im wrong on how I called the variable from previous page?
FORM 1 - that accepts the file pointer to upload. -
# Get the ID
-
$id = $_GET['id'];
-
.....
-
echo "<p>Replace CMR Document: <input type=\"file\" name=\"uploaded_file\" size=\"43\">";
-
echo "<a href='replaceCMR.php?id=$id}'>Replace";
FORM2 - the php script that will update mysql. - <?php
-
# Check if a file has been uploaded
-
if(isset($_FILES['uploaded_file']))
-
{
-
# Make sure the file was sent without errors
-
if($_FILES['uploaded_file']['error'] == 0)
-
{
-
# Connect to the database
-
.....
-
-
# Gather all required data
-
$name = mysql_real_escape_string($_FILES['uploaded_file']['name'], $dbLink);
-
$mime = mysql_real_escape_string($_FILES['uploaded_file']['type'], $dbLink);
-
$size = $_FILES['uploaded_file']['size'];
-
$data = mysql_real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name']), $dbLink);
-
-
-
# INSERT SQL query
-
$query = "
-
UPDATE fileStorage
-
SET FileName= '{$name}',
-
FileMime ='{$mime}',
-
FileSize = {$size},
-
FileData = '{$data}'
-
WHERE FileID = {$id}";
-
-
-
# Execute the INSERT QUERY
-
$result = mysql_query($query, $dbLink);
-
-
# Check if it was successfull
-
if($result)
-
{
-
echo "<b>Success! ";
-
}
-
else
-
{
-
echo "Error! Failed to updatethe file";
-
echo "<pre>". mysql_error($dbLink) ."</pre>";
-
}
-
}
-
else
-
{
-
echo "Error!
-
An error accured while the file was being uploaded.
-
Error code: ". $_FILES['uploaded_file']['error'];
-
}
-
-
}
-
else
-
{
-
echo "Error! A file was not sent!";
-
}
-
-
-
?>
4 6299
to make a little bit simple.
form - <html>
-
<body>
-
-
<form action="replaceCMR1.php" method="post"
-
enctype="multipart/form-data">
-
<label for="uploaded_file">Filename:</label>
-
<input type="file" name="file" id="file" />
-
<br />
-
<input type="submit" name="submit" value="Submit" />
-
</form>
-
-
</body>
-
</html>
uploader - <?php
-
# Check if a file has been uploaded
-
if(isset($_FILES['uploaded_file']))
-
{
-
# Make sure the file was sent without errors
-
if($_FILES['uploaded_file']['error'] == 0)
-
{
-
# Connect to the database
-
.....
-
-
# Gather all required data
-
$name = mysql_real_escape_string($_FILES['uploaded_file']['name'], $dbLink);
-
$mime = mysql_real_escape_string($_FILES['uploaded_file']['type'], $dbLink);
-
$size = $_FILES['uploaded_file']['size'];
-
$data = mysql_real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name']), $dbLink);
-
-
-
-
# INSERT SQL query
-
$query = "
-
UPDATE fileStorage
-
SET FileName= '{$name}',
-
FileMime ='{$mime}',
-
FileSize = {$size},
-
FileData = '{$data}'
-
WHERE FileID = {$id}";
-
-
-
# Execute the INSERT QUERY
-
$result = mysql_query($query, $dbLink);
-
-
# Check if it was successfull
-
if($result)
-
{
-
echo "<b>Success! Your file was successfully added!<br>";
-
echo "Email alert was sent to reviewer's group</b>";
-
-
}
-
else
-
{
-
echo "Error! Failed to insert the file";
-
echo "<pre>". mysql_error($dbLink) ."</pre>";
-
}
-
}
-
else
-
{
-
echo "Error!
-
An error accured while the file was being uploaded.
-
Error code: ". $_FILES['uploaded_file']['error'];
-
}
-
-
}
-
else
-
{
-
echo "Error! A file was not sent!";
-
}
-
-
?>
Now i was able to update the records but it's blank it looks like
below code is not working. HELP! - # Gather all required data
-
$name = mysql_real_escape_string($_FILES['uploaded_file']['name'], $dbLink);
-
$mime = mysql_real_escape_string($_FILES['uploaded_file']['type'], $dbLink);
-
$size = $_FILES['uploaded_file']['size'];
-
$data = mysql_real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name']), $dbLink);
I got it its the name on my first form should be name=uploaded_f ile
thanks!
Hi, why does this error occur:
Error:
Error! Failed to insert the file
MySQL server has gone away
I don't know what to edit anymore..
Thanks..
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Reply via newsgroup |
last post by:
Folks,
When performing an update in mysql (using PHP), can I find out how many
records were matched?
mysql_affected_rows() won't work... and I have the following problem
that I thought I could resolve with a simple function:
Example:
I have 50records - I want to update a selection of the recods - some,
|
by: Jonas Meurer |
last post by:
hello,
i develop a project with a mysql interface. one mysql table holds all
the images for my project.
everything works quite well so far, except i'm not able to upload images
into the database. the following function does the mysql UPDATE, it
requires the image and the image ID as arguments.
additionally it dumps the image to my filesystem ('/tmp/image.gif') -
|
by: red85 |
last post by:
hello i have mysql 4.1 with win2000 SP3, i know that it is only an
alpha and i don't know if someone else has already posted this
problem:
when i execute this sql
UPDATE tableX SET fieldX=valueX
WHERE id IN (SELECT tX.id FROM tableX AS tX WHERE tX.fieldY=valueY AND
filedZ=valueZ);
|
by: Fraser Hanson |
last post by:
Hello,
I have a table which has a foreign key relationship with itself. I
want and expect my updates to cascade (deletes definitely cascade as
expected) but instead I just get error 1217: foriegn key error.
I have written example code to use in reproducing the problem:
# Create the table
|
by: Jim C Nguyen |
last post by:
I have a table with ~2.2 million rows. Sometimes when I do an update
to one single row it will instead update ALL of the rows using the
same update. This happens every one in about 500,000 updates to a
single row.
I am running mysql 4.0.14 in WinXP. I am using PHP to do the update.
I am thinking something in the update itself is causing mysql to do
this. I don't have the exact SQL statement that causes the error
but I do have...
| |
by: jayson_13 |
last post by:
Hi,
I need to implement a counter and i face problem of locking so hope
that u guys can help me.
I try to do test like this :
1st connection
SELECT * FROM nextkey WHERE tblname = 'PLCN' FOR Update;
(when i execute this statement and i guess that this will lock the
|
by: Carlos Eduardo Peralta |
last post by:
Hello:
Can i update a MySQL database with just copy the files MYI MYD and FRM
in the right dir? I know this work. The question is how MySQL manage
the user that are usig that database in that moment. Can i close all
the connection to that database? How can i tell MySQL deamon that
don´t use that database any more?
Thank you in advance.
|
by: Stephen |
last post by:
Hello People,
Using MS Access 2003 VBA I get the error 3020 Update or CancelUpdate
without AddNew or Edit when I run through the following code. Can
anyone help suggest anything to try? Thanks.
On Error GoTo delete_failed
Dim RS_DEL As DAO.Recordset
|
by: roger.rigsby |
last post by:
Ok I know how to get the data I want from mysql but I need to actually
do something with this data and then send it back to mySQL.
Company heads love the spreadsheet view so this is serious business.
I've done what I could with tables and css and javascript and whatnot
for a makeshift datagrid on a webpage but since I'm using PHP and not
asp.net I have no idea how to create a datagrid.
So if anyone knows how to update data in Excel...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |