Re: entering null values
| From: | Doug Semig | Date: | Sun, 08 Oct 2000 07:19:53 +0000 |
| Subject: | Re: entering null values | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-3407@lists.php.net to get a copy of this message | ||
Two things:
First in your other posts, you were asking about what values entered into
the form would produce the NULL value in the database. Because the
**example** code snippet uses the strlen() function to see if the fields
have data, then anything (even a zero or a space) entered into the field
would be shuffled into the database. The only thing that would produce a
NULL in the database is if nothing at all were entered into the form. If
that little snippet of code was from a real project, I'd have preprocessed
the fields with input validation code, such as stripping away leading and
trailing spaces and making sure numeric fields only contained digits...that
kind of thing.
Please remember that your project is not my project. I have no idea what
the specifications for your project are, and I was only answering the
original question to the best of my knowledge. The original question had
to do with how to get NULL values into a database and your real problem was
that two apostrophes next to each other do not normally constitute a NULL
value in SQL (the SQL keyword NULL does, though), and you were somehow
thinking that addslashes() was your problem. The correct solution is to
build your SQL statement.
Second, in answer to this post, there may be typos in my original answer
and nothing is guaranteed (since I have no way to test the example snippet
without creating whole bunches of HTML and PHP code as well as making an
appropriate new table in a database...so I chose to illustrate the concept
with an example snippet). But in light of the message I'm replying to
right now, I think you may have a bit of a problem seeing the difference
between quotation marks and apostrophes. That is not your fault. It's
probably something in the character set you're displaying the snippet with.
There are never three single quotes (ummm, apostrophes) in the snippet.
Here's an example, then I'll spell it out in writing so you can see what I
was aiming for:
if (strlen($goal_1) > 0) $sql .= "'" . $goal_1 . "', ";
else $sql .= "NULL, ";
if (strlen($goal_1) > 0) $sql .= [quotation mark][apostrophe][quotation
mark] . $goal_1 . [quotation mark][apostrophe], [quotation mark];
else $sql .= [quotation mark]NULL, [quotation mark];
I replaced the " (which is one of your "double quotes") with [quotation
mark] and ' (which is one of your "single quotes") with [apostrophe].
Follow that pattern, and it should work.
I hope that clarifies it, but if not, e-mail me privately and I'll try to
help as much as I can.
Doug
At 02:25 AM 10/8/00 -0400, Scott M Wagner wrote:
>Hello
>I can't get that query to execute. How are the triple quote marks made
>in the line:
>if(strlen($id_number)>0)$sql.="".$id_number.''',";? Is it 3
>single
>quotes, a double then a single, a single then a double? In Page Burner
>it seems to be impossible to duplicate.
>
>Thanks,
>Scott Wagner