Gary White wrote:
>>
GetSQLValueString(is_array($_POST['checkbox'])?join(',',$_POST['checkbox']):$_PO
>> ST['checkbox'],"text");,
>>
> GetSQLValueString is a Dreamweaver function that will
format and add
> quotes to string values to make them work correctly in
an SQL statement.
> The code I gave you does this:
There are two problems with this:
1. If no checkbox is selected, $_POST['checkbox'] won't be
defined.
Depending on the level of error reporting in PHP, this is
likely to
trigger an error message. It will also result in the SQL
query
attempting to insert NULL into the checkbox column. Unless
the column is
defined as accepting NULL values, this will prevent the query
from
executing.
2. It edits the Dreamweaver server behavior code, which
normally
prevents you from using the Server Behavior panel to reopen
the Insert
Record dialog box. Even if it doesn't prevent you from doing
this,
Dreamweaver is likely to rewrite this code when you click OK.
You can get round the first issue by amending the code like
this:
GetSQLValueString((isset($_POST['checkbox']) &&
is_array($_POST['checkbox']))?join(',',$_POST['checkbox']):'',"text");
This adds isset() to make sure that $_POST['checkbox']
actually exists
before you try to use it, and sets the value to an empty
string if
$_POST['checkbox'] hasn't been defined.
However, this still has the disadvantage that you can't use
the Insert
Record dialog box any more. My preference is to put the code
that
formats $_POST['checkbox'] outside the server behavior. My
original
suggestion was this:
if (isset($_POST['checkbox']) &&
is_array($_POST['checkbox'])) {
$_POST['checkbox'] = implode(',', $_POST['checkbox']);
}
However, on reflection, it needs to be this:
if (isset($_POST['checkbox']) &&
is_array($_POST['checkbox'])) {
$_POST['checkbox'] = implode(',', $_POST['checkbox']);
}
else {
$_POST['checkbox'] = '';
}
If you put this in a separate code block right at the top of
the page,
the Dreamweaver server behavior remains fully editable in the
Insert
Record dialog box, but you get the result that you want.
The difference between Gary's code and mine is that he uses
the
conditional operator instead of an if... else statement, and
join()
instead of implode(). The two functions are identical.
If you want to use the conditional operator, my version of
the code
looks like this:
$_POST['checkbox'] = (isset($_POST['checkbox']) &&
is_array($_POST['checkbox'])) ? implode(',',
$_POST['checkbox']) : '';
--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/