Re: [newbie] Keeping it all in one page?



On Tue, 29 Jan 2008 20:53:29 -0500, Jerry Stuckle
<jstucklex@xxxxxxxxxxxxx> wrote:
And adding a checkbox isn't hard at all. But don't just use
the primary key id in the checkbox unless you have some other way
to protect your page from hackers.

The definitive wrong way to do things:
============
<?php

switch ($status) {
case "delete":
foreach ($item as $bit) {
$query = "DELETE FROM " . $table . " WHERE id=" . $bit;
$result = mysql_query($query) or die("Query failed: " .
mysql_error());
}
break;

default:
echo "<form method=post>";
echo "<input type=checkbox name=item[] value=1>"
echo "<input type=checkbox name=item[] value=2>"
echo "<input type=hidden name=status value=delete>";
echo "<input type=submit value=Delete>";
echo "</form>";

}
?>
============

BTW, is there some book like "The 50 pitfalls of writing web apps in
PHP" that would take real-life newbie errors like the above, explain
why they're wrong, and the safe way to rewrite them?

Thanks.
.



Relevant Pages

  • Re: [newbie] Keeping it all in one page?
    ... use the primary key id in the checkbox unless you have ... some other way to protect your page from hackers. ...
    (comp.lang.php)
  • Re: How do get the state of checkboxes in php?
    ... each of their states into PHP after submitting the page. ... In almost all cases you'll want the hidden input to ... appear in the source before the actual checkbox. ... "Working with Checkboxes in PHP ...
    (comp.lang.php)
  • Re: help with POST
    ... Categories from the database but I'm having trouble passing the ... name/value of the checkbox. ... Doing so will force PHP to parse that incoming ... You might want to run a query like that manually against your database ...
    (php.general)
  • Re: How to protect data in other directories
    ... members only. ... or even php scripts) he can access them easily. ... I'm assuming these are not PHP files. ... If that's impossible, then second best is to protect the directory with ..htaccess so the files can't be accessed by anyone. ...
    (alt.php)
  • RE: if..else condition for checkbox
    ... unless you only wanted to see if the Cash, Nets, OR Cheque checkbox was ... If you don't, PHP assumes you ... I have attached my HTML ... <div class="sectionheading"> ...
    (php.general)