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

displaying email without attracting a ton of spam
Hello,

this is maybe the wrong place to ask.
How would you display an email address on a w

a dificult string search
Hi I don't know a way around this. I want the user to input a password, but to make it a bit complca

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

How To Make More Than One Redirection with PHP on the same page?
Hey im trying to do a direction page where it open differently link direction pages every time som

PHP and Javascript
Hi Guys,

Im trying to load the contents of an html file into a text area for editing, this is

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

<?php
mysql_connect

SWF image using php?
Hello once again.

My latest en devour requires me to produce an image of a static .swf that i

Help with ORDER BY
Hello. I would like to order by ascending States, then Cities, then Gyms in the following code, but

Help: calling function
Hi,
Is it possible to call a php function on page close?
If yes, could you explain how and whe

PHP Game
hy i was wondering what's the best method in order to make some automatic updates in a php game
<

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