Skip to main content
Known Participant
October 10, 2006
Question

MySQL Not Null not working as I expect

  • October 10, 2006
  • 1 reply
  • 795 views
Hi,

I've created a form to try and stop some autobot spamming that has been occuring.

I have created a dropdown option field where the person filling out the form has to choose the second option which is like:

1. I am a computer
2. I am a Human.

The default option is 1, and using Yaromats extension, I have set it so that the first option is not correct and will return and error etc.

This all works fine.

The field in the MySQL database that gets populated by the choice is called comments_Secure.

I have set it that the field is "Not Null", which, in my understanding means that the entry will not be accepted unless the field is populated, a bit like the Primary key field but is set to auto-increment so that is will automatically be filled.

However, if I do not choose the correct option in the drop down menu on the Form page, then indeed I get the error to choose the correct option or I cannot submit the form.

This seems to be somewhat different to the way the autobot spam works, because I have found that it will still create an entry in the database, but the comment_Secure filed is empty and not populated, but the MySQL database seems to accept this.

If I fill out an entry directly in phpMyAdmin, it too accepts the entry even if I do not populate the comment_secure field.

What am I overlooking here please?

Can you please explain how to set it up so that the comment_Secure field has to have text inserted or the entry is not accepted???

cheers
This topic has been closed for replies.

1 reply

Inspiring
October 10, 2006
why not just place a submit if not = 1 in your code instead of in the SQL?

If you do it in the SQL, then you're still going to have to create an error
page to deal with it (in case a human forgets to change it).


"Macnimation" <webforumsuser@macromedia.com> wrote in message
news:eggoeh$lfg$1@forums.macromedia.com...
> Hi,
>
> I've created a form to try and stop some autobot spamming that has been
> occuring.
>
> I have created a dropdown option field where the person filling out the
> form
> has to choose the second option which is like:
>
> 1. I am a computer
> 2. I am a Human.
>
> The default option is 1, and using Yaromats extension, I have set it so
> that
> the first option is not correct and will return and error etc.
>
> This all works fine.
>
> The field in the MySQL database that gets populated by the choice is
> called
> comments_Secure.
>
> I have set it that the field is "Not Null", which, in my understanding
> means
> that the entry will not be accepted unless the field is populated, a bit
> like
> the Primary key field but is set to auto-increment so that is will
> automatically be filled.
>
> However, if I do not choose the correct option in the drop down menu on
> the
> Form page, then indeed I get the error to choose the correct option or I
> cannot
> submit the form.
>
> This seems to be somewhat different to the way the autobot spam works,
> because
> I have found that it will still create an entry in the database, but the
> comment_Secure filed is empty and not populated, but the MySQL database
> seems
> to accept this.
>
> If I fill out an entry directly in phpMyAdmin, it too accepts the entry
> even
> if I do not populate the comment_secure field.
>
> What am I overlooking here please?
>
> Can you please explain how to set it up so that the comment_Secure field
> has
> to have text inserted or the entry is not accepted???
>
> cheers
>


Known Participant
October 10, 2006
Hi,
Thank for the quick response.

Where in the code would I put this option please?

I could be wrong, but I don't think the automated spam entries are actually going through the form, but directly into the MySql database, because the dropdown option is a required field and this works fine if I choose the second option of "I am a Human" but I get the error if I leave the default "I am a Computer" as it is.

But, If I go into the MySql database directly, I can leave it blank and it creates the entry, totally ignoring the required field. Thats why I thought to secure it at the database level rather than the php form page.

Cheers
Known Participant
October 11, 2006
Thanks again for the responses.

Would I just place the first line of that code above the Form tag like?:

if($_POST['CheckedField'] ==2){

<form>
Form fields
</form>

}else{
put redirect here;}

I would then change the textfield to a standard input field instead of the dropdown menu options. If the user puts the number 2 into the field then it will accept this?

Cheers