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

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

Redirecting Admin
In my members table, I have a field called "perm" and it's set to zero for all members. Ho

Can I call a class inside a function?
I have a class written in another file that handles my image resizing.

Can I do this (php say

Packet Design
Hi All,
Im new about network programming and I want to design a protocol but I have some question

Php - mysql store data and use it later?
Hi, i' making a login page at the moment, however my username + password is stored many different pl

Setting/Modify Headers using mail() function
I have a question about setting email headers when using mail() in a php script.

When I send

insert PHP code into function
Hi,
I'm having problems when trying following:

I have:
Code: [Select]createBar("Do

reading partial code from external site
Hi,

I am trying to write a script for my website to get an article from an external website.

Login Functionality Working Different on IE
This is an odd one, I have a site which has an admin section. The admin pages unsurprisingly require

Please help understand this code
I noticed the index page on my site was modified this morning and found this code inserted at the bo

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