473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Upload a file question

Hi all.

Im a newbie in PHP and im trying to upload a file to the server.

I use a form to upload a pdf file and some text information about it.

The client uploads the file and the system renames that file and puts
all the information in the database.

The problem is when the client goes again to edit the information, i
always have to choose a file to upload or else it will put blank the
pdf column and he cant find the old one!

i do a $_POST['file'] to the UPDATE statement but i think i need to do
a if clause(and dont know what im going to put )...but where? i tried
it in the UPDATE statement and i cant..
Jun 27 '08 #1
10 1444
On Jun 20, 10:54*am, Pépê <josemariabar...@gmail.comwrote:
Hi all.

Im a newbie in PHP and im trying to upload a file to the server.

I use a form to upload a pdf file and some text information about it.

The client uploads the file and the system renames that file and puts
all the information in the database.

The problem is when the client goes again to edit the information, i
always have to choose a file to upload or else it will put blank the
pdf column and he cant find the old one!

i do a $_POST['file'] to the UPDATE statement but i think i need to do
a if clause(and dont know what im going to put )...but where? i tried
it in the UPDATE statement and i cant..
Build your update statement dynamically. This is the sort of thing,
but you should sanitise the $_POST input.

if($_POST['file'])
$fileup = ",file = '{$_POST['file']}'";
else
$fileup = '';

$qry = "
INSERT INTO fred SET
id = {$id},
info1 = '{$info1}',
info2 = '{$info2}
{$fileup}
ON DUPLICATE KEY UPDATE
info1 = '{$info1}',
info2 = '{$info2}'
{$fileup}
";

Jun 27 '08 #2
Thanks for the help Captain.

Ive had some problems recently with sql injection in ASP.

Im new in PHP. How can i protect the forms in PHP?

I will do a search in google in the meantime...

Once again, thanks

On 20 Jun, 11:22, Captain Paralytic <paul_laut...@yahoo.comwrote:
On Jun 20, 10:54*am, Pépê <josemariabar...@gmail.comwrote:
Hi all.
Im a newbie in PHP and im trying to upload a file to the server.
I use a form to upload a pdf file and some text information about it.
The client uploads the file and the system renames that file and puts
all the information in the database.
The problem is when the client goes again to edit the information, i
always have to choose a file to upload or else it will put blank the
pdf column and he cant find the old one!
i do a $_POST['file'] to the UPDATE statement but i think i need to do
a if clause(and dont know what im going to put )...but where? i tried
it in the UPDATE statement and i cant..

Build your update statement dynamically. This is the sort of thing,
but you should sanitise the $_POST input.

if($_POST['file'])
* $fileup = ",file = '{$_POST['file']}'";
else
* $fileup = '';

$qry = "
INSERT INTO fred SET
* id = {$id},
* info1 = '{$info1}',
* info2 = '{$info2}
* {$fileup}
ON DUPLICATE KEY UPDATE
* info1 = '{$info1}',
* info2 = '{$info2}'
* {$fileup}
";
Jun 27 '08 #3
Pépê wrote:
Thanks for the help Captain.

Ive had some problems recently with sql injection in ASP.

Im new in PHP. How can i protect the forms in PHP?
Look up mysql_real_escape_string
Jun 27 '08 #4
On Jun 20, 11:33*am, Pépê <josemariabar...@gmail.comwrote:
On 20 Jun, 11:22, Captain Paralytic <paul_laut...@yahoo.comwrote:
On Jun 20, 10:54*am, Pépê <josemariabar...@gmail.comwrote:
Hi all.
Im a newbie in PHP and im trying to upload a file to the server.
I use a form to upload a pdf file and some text information about it.
The client uploads the file and the system renames that file and puts
all the information in the database.
The problem is when the client goes again to edit the information, i
always have to choose a file to upload or else it will put blank the
pdf column and he cant find the old one!
i do a $_POST['file'] to the UPDATE statement but i think i need to do
a if clause(and dont know what im going to put )...but where? i tried
it in the UPDATE statement and i cant..
Build your update statement dynamically. This is the sort of thing,
but you should sanitise the $_POST input.
if($_POST['file'])
* $fileup = ",file = '{$_POST['file']}'";
else
* $fileup = '';
$qry = "
INSERT INTO fred SET
* id = {$id},
* info1 = '{$info1}',
* info2 = '{$info2}
* {$fileup}
ON DUPLICATE KEY UPDATE
* info1 = '{$info1}',
* info2 = '{$info2}'
* {$fileup}
Thanks for the help Captain.

Ive had some problems recently with sql injection in ASP.

Im new in PHP. How can i protect the forms in PHP?

I will do a search in google in the meantime...

Once again, thanks
Please do not top post (top posting fixed).

Your main tool for this is mysql_real_escape_string(), but you will
find lots of good threads about this subject in the archives of this
forum.
Jun 27 '08 #5
sheldonlg wrote:
Pépê wrote:
>Thanks for the help Captain.

Ive had some problems recently with sql injection in ASP.

Im new in PHP. How can i protect the forms in PHP?

Look up mysql_real_escape_string

I'm new to php also.

Wouldn't that be unnecessary with PDO and placeholders?

It is with perl DBI that strongly resembles PDO and I'd like to know
if I'm mistaken.

Jeff
Jun 27 '08 #6
On Fri, 20 Jun 2008 14:17:27 +0200, Jeff <jeff@spam_me_not.comwrote:
sheldonlg wrote:
>Pépê wrote:
>>Thanks for the help Captain.

Ive had some problems recently with sql injection in ASP.

Im new in PHP. How can i protect the forms in PHP?
Look up mysql_real_escape_string


I'm new to php also.

Wouldn't that be unnecessary with PDO and placeholders?
If you indeed use prepared statments, then yes, it is not necessary to use
mysql_real_escape_string(). It would be destructive even, as your
variables in the database could be polluted with unnecessary (and unused)
escaping characters.
--
Rik Wasmus
....spamrun finished
Jun 27 '08 #7
On 20 Jun, 11:22, Captain Paralytic <paul_laut...@yahoo.comwrote:
On Jun 20, 10:54*am, Pépê <josemariabar...@gmail.comwrote:
Hi all.
Im a newbie in PHP and im trying touploada file to the server.
I use a form touploada pdf file and some text information about it.
The client uploads the file and the system renames that file and puts
all the information in the database.
The problem is when the client goes again to edit the information, i
always have to choose a file touploador else it will put blank the
pdf column and he cant find the old one!
i do a $_POST['file'] to the UPDATE statement but i think i need to do
a if clause(and dont know what im going to put )...but where? i tried
it in the UPDATE statement and i cant..

Build your update statement dynamically. This is the sort of thing,
but you should sanitise the $_POST input.

if($_POST['file'])
* $fileup = ",file = '{$_POST['file']}'";
else
* $fileup = '';

$qry = "
INSERT INTO fred SET
* id = {$id},
* info1 = '{$info1}',
* info2 = '{$info2}
* {$fileup}
ON DUPLICATE KEY UPDATE
* info1 = '{$info1}',
* info2 = '{$info2}'
* {$fileup}
";
Hi Captain,

I tried what you ve done but with the update statment:

if($_POST['relatorio_pdf']){
$fileup = ",relatorio_pdf = '{$_POST['relatorio_pdf']}'";
}else{
$fileup = '';

if (empty($error) ) {

$sql = "UPDATE relatorio SET
relatorio_nome = '{$_POST['relatorio_nome']}',
relatorio_ano = '{$_POST['relatorio_ano']}',
relatorio_pdf = '$fileup',
relatorio_activo = '{$_POST['relatorio_activo']}'
WHERE relatorio_id = {$_GET['relatorio_id']}";
}
But it didnt worked..

And i didnt quite understand this line: $fileup = ",relatorio_pdf =
'{$_POST['relatorio_pdf']}'"; (why the comma, and then a variable name?
Jun 27 '08 #8
Pépê wrote:
On 20 Jun, 11:22, Captain Paralytic <paul_laut...@yahoo.comwrote:
>On Jun 20, 10:54 am, Pépê <josemariabar...@gmail.comwrote:
>>Hi all.
Im a newbie in PHP and im trying touploada file to the server.
I use a form touploada pdf file and some text information about it.
The client uploads the file and the system renames that file and puts
all the information in the database.
The problem is when the client goes again to edit the information, i
always have to choose a file touploador else it will put blank the
pdf column and he cant find the old one!
i do a $_POST['file'] to the UPDATE statement but i think i need to do
a if clause(and dont know what im going to put )...but where? i tried
it in the UPDATE statement and i cant..
Build your update statement dynamically. This is the sort of thing,
but you should sanitise the $_POST input.

if($_POST['file'])
$fileup = ",file = '{$_POST['file']}'";
else
$fileup = '';

$qry = "
INSERT INTO fred SET
id = {$id},
info1 = '{$info1}',
info2 = '{$info2}
{$fileup}
ON DUPLICATE KEY UPDATE
info1 = '{$info1}',
info2 = '{$info2}'
{$fileup}
";

Hi Captain,

I tried what you ve done but with the update statment:

if($_POST['relatorio_pdf']){
$fileup = ",relatorio_pdf = '{$_POST['relatorio_pdf']}'";
}else{
$fileup = '';

if (empty($error) ) {

$sql = "UPDATE relatorio SET
relatorio_nome = '{$_POST['relatorio_nome']}',
relatorio_ano = '{$_POST['relatorio_ano']}',
relatorio_pdf = '$fileup',
relatorio_activo = '{$_POST['relatorio_activo']}'
WHERE relatorio_id = {$_GET['relatorio_id']}";
}
But it didnt worked..

And i didnt quite understand this line: $fileup = ",relatorio_pdf =
'{$_POST['relatorio_pdf']}'"; (why the comma, and then a variable name?
That's because you use UPDATE instead of INSERT.

INSERT adds a new row to the database (or, as a MySQL extension, updates
a current row). UPDATE only changes a row which already exists; it does
not add a new row.

Additionally,

$fileup = ",relatorio_pdf = '{$_POST['relatorio_pdf']}'"

is part of the SQL statement. Do you have a column named
'relatorio_pdf' in your table? Also, is the field name in your form
'relatorio_pdf'? If the answer to both is yes, then this code is
correct. Otherwise, this is a problem.

And finally, when you get your code to what Paul showed you, "it's not
working" isn't much help. What errors do you get?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 27 '08 #9
On 24 Jun, 12:46, Jerry Stuckle <jstuck...@attglobal.netwrote:
Pépê wrote:
On 20 Jun, 11:22, Captain Paralytic <paul_laut...@yahoo.comwrote:
On Jun 20, 10:54 am, Pépê <josemariabar...@gmail.comwrote:
>Hi all.
Im a newbie in PHP and im trying touploada file to the server.
I use a form touploada pdf file and some text information about it.
The client uploads the file and the system renames that file and puts
all the information in the database.
The problem is when the client goes again to edit the information, i
always have to choose a file touploador else it will put blank the
pdf column and he cant find the old one!
i do a $_POST['file'] to the UPDATE statement but i think i need to do
a if clause(and dont know what im going to put )...but where? i tried
it in the UPDATE statement and i cant..
Build your update statement dynamically. This is the sort of thing,
but you should sanitise the $_POST input.
if($_POST['file'])
* $fileup = ",file = '{$_POST['file']}'";
else
* $fileup = '';
$qry = "
INSERT INTO fred SET
* id = {$id},
* info1 = '{$info1}',
* info2 = '{$info2}
* {$fileup}
ON DUPLICATE KEY UPDATE
* info1 = '{$info1}',
* info2 = '{$info2}'
* {$fileup}
";
Hi Captain,
I tried what you ve done but with the update statment:
* * * * * * * * * * * * * * * * * *if($_POST['relatorio_pdf']){
* * * * * * * * * * * * * * * * * ** $fileup = ",relatorio_pdf = '{$_POST['relatorio_pdf']}'";
* * * * * * * * * * * * * * * * * *}else{
* * * * * * * * * * * * * * * * * ** $fileup = '';
* * * * * * * * * * * * * * * * * *if (empty($error) ) {
* * * * * * * * * * * * * * * * * ** * * *$sql = "UPDATE relatorio SET
* * * * * * * * * * * * * * * * * ** * * * * * * * * relatorio_nome = '{$_POST['relatorio_nome']}',
* * * * * * * * * * * * * * * * * ** * * * * * * * * relatorio_ano = '{$_POST['relatorio_ano']}',
* * * * * * * * * * * * * * * * * ** * * * * * * * * relatorio_pdf = '$fileup',
* * * * * * * * * * * * * * * * * ** * * * * * * * * relatorio_activo = '{$_POST['relatorio_activo']}'
* * * * * * * * * * * * * * * * * ** * * * * * * *WHERE relatorio_id = {$_GET['relatorio_id']}";
* * * * * * * * * * * * * * * * * *}
But it didnt worked..
And i didnt quite understand this line: $fileup = ",relatorio_pdf =
'{$_POST['relatorio_pdf']}'"; (why the comma, and then a variable name?

That's because you use UPDATE instead of INSERT.

INSERT adds a new row to the database (or, as a MySQL extension, updates
a current row). *UPDATE only changes a row which already exists; it does
not add a new row.

Additionally,

$fileup = ",relatorio_pdf = '{$_POST['relatorio_pdf']}'"

is part of the SQL statement. *Do you have a column named
'relatorio_pdf' in your table? *Also, is the field name in your form
'relatorio_pdf'? *If the answer to both is yes, then this code is
correct. *Otherwise, this is a problem.

And finally, when you get your code to what Paul showed you, "it's not
working" isn't much help. *What errors do you get?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Thanks Jerry, yes everything was working in SQL. It was an error with
PHP.ini about filesize ...

Other question, an attacker can insert sql injection through an INSERT
or UPDATE statement?

Because im reading a book about security in SQL and he uses the secury
method only to SELECT statements like in this example:

$query = sprintf('SELECT field FROM table WHERE FIELD_ID = %d',
$_POST['field_id']);

Jun 27 '08 #10
Pépê wrote:
On 24 Jun, 12:46, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Pépê wrote:
>>On 20 Jun, 11:22, Captain Paralytic <paul_laut...@yahoo.comwrote:
On Jun 20, 10:54 am, Pépê <josemariabar...@gmail.comwrote:
Hi all.
Im a newbie in PHP and im trying touploada file to the server.
I use a form touploada pdf file and some text information about it.
The client uploads the file and the system renames that file and puts
all the information in the database.
The problem is when the client goes again to edit the information, i
always have to choose a file touploador else it will put blank the
pdf column and he cant find the old one!
i do a $_POST['file'] to the UPDATE statement but i think i need to do
a if clause(and dont know what im going to put )...but where? i tried
it in the UPDATE statement and i cant..
Build your update statement dynamically. This is the sort of thing,
but you should sanitise the $_POST input.
if($_POST['file'])
$fileup = ",file = '{$_POST['file']}'";
else
$fileup = '';
$qry = "
INSERT INTO fred SET
id = {$id},
info1 = '{$info1}',
info2 = '{$info2}
{$fileup}
ON DUPLICATE KEY UPDATE
info1 = '{$info1}',
info2 = '{$info2}'
{$fileup}
";
Hi Captain,
I tried what you ve done but with the update statment:
if($_POST['relatorio_pdf']){
$fileup = ",relatorio_pdf = '{$_POST['relatorio_pdf']}'";
}else{
$fileup = '';
if (empty($error) ) {
$sql = "UPDATE relatorio SET
relatorio_nome = '{$_POST['relatorio_nome']}',
relatorio_ano = '{$_POST['relatorio_ano']}',
relatorio_pdf = '$fileup',
relatorio_activo = '{$_POST['relatorio_activo']}'
WHERE relatorio_id = {$_GET['relatorio_id']}";
}
But it didnt worked..
And i didnt quite understand this line: $fileup = ",relatorio_pdf =
'{$_POST['relatorio_pdf']}'"; (why the comma, and then a variable name?
That's because you use UPDATE instead of INSERT.

INSERT adds a new row to the database (or, as a MySQL extension, updates
a current row). UPDATE only changes a row which already exists; it does
not add a new row.

Additionally,

$fileup = ",relatorio_pdf = '{$_POST['relatorio_pdf']}'"

is part of the SQL statement. Do you have a column named
'relatorio_pdf' in your table? Also, is the field name in your form
'relatorio_pdf'? If the answer to both is yes, then this code is
correct. Otherwise, this is a problem.

And finally, when you get your code to what Paul showed you, "it's not
working" isn't much help. What errors do you get?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Thanks Jerry, yes everything was working in SQL. It was an error with
PHP.ini about filesize ...

Other question, an attacker can insert sql injection through an INSERT
or UPDATE statement?

Because im reading a book about security in SQL and he uses the secury
method only to SELECT statements like in this example:

$query = sprintf('SELECT field FROM table WHERE FIELD_ID = %d',
$_POST['field_id']);

Yes, UPDATE and INSERT statements are even more dangerous - SELECT
allows him to possibly see things he couldn't. INSERT/UPDATE allows him
to CHANGE things to what he shouldn't.

For instance - I had a customer about 2-3 years ago who was running
PHPBB2 on his site. He didn't keep up with the security fixes, and one
day a hacker went in and defaced the entire BBS. Fortunately, no data
was lost and after a couple of hours determining just what had been
changed, I was able to get into the database and fix it, with no loss of
data. Then I upgraded his PHPBB2 to the latest version. He now keeps
it updated.

But because of a security breach in an UPDATE statement, someone was
able to hack it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 27 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
1
by: joshbeall | last post by:
Hi All, If I drop a form onto my page that allows file uploads, I know well enough how to handle the file upload in the server side via PHP. However, I have a question: when my browser...
1
by: Marko Vuksanovic | last post by:
I used the following code for implementing a file upload progress indicator, using UpdateProgress Panel, though I have a problem that FileUpload.Has File always returns false. Any suggestions what...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
6
by: =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes | last post by:
I have a strange problem when uploading a PDF document to a web-server. When I try this to a web-server running Apache 2 on a FC 4, it fails. Firefox says that the document contain no data. If I...
2
by: will.smothers | last post by:
All, I have two Windows Server 2003 boxes running IIS 6.0 webservers that host our proxy pac file. These two servers are behind a network load- balancer and house our corporation's Proxy PAC file....
1
by: lPrentice | last post by:
Hello, After all this time, Linux file permissions still confuse me at times. I have a Python web-based application with an file (images) upload module. The application is running on two remote...
12
by: GuangXiN | last post by:
I want the file upload element disappear, instead of it, I place a text box and a button with my own css defination. but it doesn't work on IE7. What should I do now? <form action="upload.php"...
43
by: bonneylake | last post by:
Hey Everyone, Well this is my first time asking a question on here so please forgive me if i post my question in the wrong section. What i am trying to do is upload multiple files like gmail...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
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...
0
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.