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

Problems with adding a link to one position in a 'foreach' loop, please help
Hello!

Iam pretty new to programming and I wanna create a table with users from an array. It

Php - mysql select?
hi, i have this code:

Code: <?php
session_start();
// dBase file
include &quo

Pls help with PHP
Pls can anyone direct me on how to create a user account for a customer. For example i want know if

printing links
Hi every1

i am connecting to a table in sql and the looping through with a while ($ var = my

Multithreading in Oracle (Java, SQLJ, Pro*C,??) on 10g
I am investigating how to run a Java stored procedure in multithread mode.
I know that if I chang

php wont update my db
hello,

sorry for posting in mysql forum but i dont know where exactly is the problem but here

radio button reamains checked
Hello i'm trying to keep the state off my radio buttons so it shows which ones where clicked after t

Reading waves
Hi,

I am trying to find a way of finding the highs and lows on a graph line, the line points

Problems with strings containing
Hey all,

I have encountered something strange in a script. I am trying to write an XML heade

PHP form authentication
Hi guys,

what am trying to achieve is this: Whenever a user tries to login to my website, an

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