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

How to form a xml form table with a single sql statement..?
Hi everyone,
I don't know if this is going to be a duplicate thread but i couldn't

Problem!
I have another problem, when i run this code i get this error "Parse error: syntax error, unexp

PHP Cannot redeclare class
I have 6 files, and two of them do not seem to want to play well. I keep getting a "Cannot rede

Opening Multiple Files/Links in Order.
I want to open links in order/one-by-one and check each for a specific string.

Example:
I

scandir clients directory
hi,
how can i scandir the clients directory? i need a script that when i click a button it will u

EXplanation help
Hey all,

I am still fairly new to PHP programming and I am trying to put together a page wher

Loops and Classes
I am making a template system and everything seems to be going well up until I have to loop in a var

Storing Values taken from a DB...
Using this code it will generate a short list from my database

<?php
mysql_connect

if statements problems
Hi. I'm trying to make a web form, but I kind of hit a dead end trying to figure out why it doesn't

foreach help.
Hello all,

First time I'm attempting to use a foreach statement and was just wondering if my

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