PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Upload a file question
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Upload a file question

Réponse
 
LinkBack Outils de la discussion
Vieux 20/06/2008, 10h54   #1
Pépê
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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..
  Réponse avec citation
Vieux 20/06/2008, 11h22   #2
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Upload a file question

On Jun 20, 10:54am, Pépê <josemariabar...@gmail.com> wrote:
> 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}
";

  Réponse avec citation
Vieux 20/06/2008, 11h33   #3
Pépê
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Upload a file question

Thanks for the 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.com> wrote:
> On Jun 20, 10:54am, Pépê <josemariabar...@gmail.com> wrote:
>
>
>
> > 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}
> ";


  Réponse avec citation
Vieux 20/06/2008, 12h10   #4
sheldonlg
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Upload a file question

Pépê wrote:
> Thanks for the 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
  Réponse avec citation
Vieux 20/06/2008, 12h19   #5
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Upload a file question

On Jun 20, 11:33am, Pépê <josemariabar...@gmail.com> wrote:
> On 20 Jun, 11:22, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> > On Jun 20, 10:54am, Pépê <josemariabar...@gmail.com> wrote:

>
> > > 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 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.
  Réponse avec citation
Vieux 20/06/2008, 13h17   #6
Jeff
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Upload a file question

sheldonlg wrote:
> Pépê wrote:
>> Thanks for the 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
  Réponse avec citation
Vieux 20/06/2008, 18h19   #7
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Upload a file question

On Fri, 20 Jun 2008 14:17:27 +0200, Jeff <jeff@spam_me_not.com> wrote:

> sheldonlg wrote:
>> Pépê wrote:
>>> Thanks for the 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
  Réponse avec citation
Vieux 24/06/2008, 11h56   #8
Pépê
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Upload a file question

On 20 Jun, 11:22, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On Jun 20, 10:54am, Pépê <josemariabar...@gmail.com> wrote:
>
>
>
> > 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?
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h10.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,24336 seconds with 16 queries