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

login page does not execute a else statement
I've created a login page using sessions.
When an incorrect user name or password is entered then

Fetching META TAGS through
Hello everybody
I want to fetch meta tags of a domain.
It will be done from following code of

sql error
I have been looking at this code for 20mins and can't work out what I am doing wrong. There is somet

array_combine() trouble w/csv file
I have a problem with a piece of code I wrote to import some records from a csv file into mysql. I h

Staff Induction System - No idea where to go from here!!!
Hi there, I'm pretty new to PHP and Mysql so could really do with being pointed in the right directi

A little help needed passing hidden values to next page
I have a page that has hidden values in a form.

example
Code: <input name='signupID

SMTP server...
I recently found a tutorial online on SMTP authentification for sending emails from webpages, here i

database design
Hi,

I got a page which allow candidate to type in their previous working experience,
I let

Option box to change variable
Hello, i need help by making a script!

I need to write a file with option box, so a dropdown

How to secure my login data to my database?
Hi there,

It may be a stupid question but I don't know how to secure my login data to my data

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