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

Mail sending is slow on server
Why mail is taking time to be send on apache-linux server

Form errors in an array
I'm processing a form and putting the errors in an array. empty($errors) doesn't seem to do the tric

php global variable
how can we create global variable so we can use its value in any form.. Please give example to

Add 5 to a variable when a button is clicked, and re-run a for loop
So I'm making a feedback sort of section on a website with MySQL and PHP, I've gotten the script to

C++ Http request?
Code: string Response = "LOGIN_UNSUCCESSFUL"; System.Net.WebRequest request = Sy

Xacute search within SQL results
I have a query that is pulling data, and I want to return a specific value from the results of that

Help building / using array
First - this is a cross-posting, if this is wrong I apologise! What started out as a MySQL query que

mod_rewrite.c on windows ??
why it's not working on windows while it's working on other hosts???

this is the code i got

Get Total From While Loop
I'm trying to get the total for each product and add them for a Grand Total to list outside the loop

include
Hi I have this way of licensing my PHP application, and I want to know if you guys can answer some q

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