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

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

Generate PDF
Hi guys,

I would like to know if there is a way to generate pdf when clicking on a link. In f

Something like an INI editor or a DelimitedText-Editor
Hi all,

Am very, very, very new to PHP and not sure if I should be posting this to a Javascri

php include email form with attachment
I have had no luck with finding a email form all over the Internet for various reasons. Some insecur

DYNPRO_FIELD_CONVERSION
Hi gurus,

I got a dump when I run one of my program. the dump is described below:

Php WordPress help
I am writing the following code for making a plugin

<?php
header("Content-Type

User registration and login
I don't know whether this is the correct forum, if not i apologise but am pretty desperate at the mo

Allowing ' and "
Hello everyone,

I am creating a form where users submit information to go into a database. I

Join Query Help
Hi all,

I am having problems with the below code, which we shall call 'my first join query'!

empty() error
Why does

Code: empty($USER_ID = $_SESSION["USER_ID"])
create this error...

Upload simple problem
Really confused!! I run once and it worked, but when i tried today...it didn't work

Which par

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