Form validation with functions


Posted on 16th Feb 2014 07:03 pm by admin

Hi there

I am trying to make a very simple form validation function. I currently have the following

Did you know?Explore Trending and Topic pages for more stories like this.
function formValidate($field, $msg) {

if (empty($_POST['$field'])) {
$errors[] = $msg;
} else {
$field = mysqli_real_escape_string($dbc, trim($_POST['$field']));
}

}// end of function

formValidate('form', 'You forgot to enter the form');


When I run the script and enter nothing into the $_POST['form'] field it still executes an empty record into the database.

What am I doing wrong?
No comments posted yet

Your Answer:

Login to answer
169 Like 33 Dislike
Previous forums Next forums
Other forums

Apart from cron
I need to run a php file every one hour. Is there any other solution apart from cron job?

The repetition structure: the while statement not working
New programming student, have assignment as follows:
A restaurant has 4 lunch combos for custom

Need help PLEASE
ok i have this warning showing up

Warning: in_array() [function.in-array]: Wrong datatype for

weeks in a year
hi,

i found this snippet on php.net
QuoteFor the week number for weeks starting on Sunday:

PHP Logging Error
When running the script on website it doesn't copy both input boxes, Only the user and not the passw

selection tool on raster image
Hi!
I have to implement in my app a selection tool which lets users to select region of any shape

Onclick problem in Firefox
Hi,
I am using a . It doesn't seem to

$get problem
Hi Guys ...

can you please tell me what i am doing wrong here
Code: <?php

Multiple forms on the same page (safari)
Hello everyone,

I have 3 forms on the same page, that opens in a new window and submits to a

Just a white page
Okay so, my website, when I click SignUp on it it takes me to /join.php but its a complete white pag

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash