Reply to Re: Newbie - Help please with printing $_POST array

Your name:

Reply:


Posted by Dynamo on 05/18/06 17:21

Absolutely spot on!! Many many thanks. I read your comments on html 4.01 spec
and modified my input page accordingly. Then used $delete = '( id = ' .
implode(' OR id = ', $_POST['delete'] ) . ' ) '; in my query and it worked first
time.

Regards
Dynamo

In article <J1_ag.1469$KH1.188@reader1.news.jippii.net>, Kimmo Laine says...
>
>$delete = '( id = ' . implode(' OR id = ', array_keys($_POST)) . ' ) ';
>
>// implode takes all elements of the array and joins them with the given
>string, so that "1,2,3" becomes " 1 OR id = 2 OR id = 3 " and then we add a
>little something in both ends and it's good to go.
>
>$query1="DELETE FROM Catalogue WHERE $delete";
>mysql_query($query1) or die("Failed Query of " . $query1);
>
>But may I just say a few things about your form. The html 4.01 specification
>does not allow using numbers as names of input elements, so having input
>like
><input type='checkbox' name='62' value='ON'> is wrong since 62 is a number.
>It should at least start with an underscore or an alphabet. Next thing is
>that you now have to use the keys of the $_POST array as values. That might
>lead into trouble too. I suggest you start using something more like this:
>
><input type='checkbox' name='delete[]' value='<?php echo $row[0];?>'>
>
>When you use a name like delete[], php creates an array of these elements
>under $_POST['delete']. You gotta keep 'em separated from other variables
>that come from the form and this is how you do it. Now your form has no
>other elements, but in future you might end up doing something like that. So
>it's good if you start doing things the right way now. ;)
>
>Now your query would look like this:
>$delete = '( id = ' . implode(' OR id = ', $_POST['delete'] ) . ' ) ';
>
>All input elements should have a proper name, therefore your submit should
>also be named, <input type="submit" name="submit" value="Test">
>


--
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация