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 display objects in a row
I have 7 codes that i want to display in a row one next to another.
The first is {$ads->ad

array_map() probably obvious mistake
The code below is part of a class to escape strings, but should also accept an array, using array_ma

how make 2 column in table with data tybe long row
hi every one

I want make in my table 2 column with data tybe long raw

how thi

Delete records not in top 15
Hi,

I'm creating a hall of fame page in my game and the page will only display the top 15 sco

PHP Directory Listing Not working
Hey Guys,

I need help, I tried a ton of directory listing scripts and they all don't work. Al

PHP Code reffering to database, doing something wrong.. pls help
Well i am quite new with PHP
and for school we have to make a PHP script which reffers to a Data

How to create a static html menu from a database
Hi,

I have built a small cms which allows me to create simple html pages and then upload them

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

upload only text files
hi guys i want to upload only text like like (pdf,note pad and ofiice files) so can any one please t

Login logout link help
Hi all,

Im new to php and Im having trouble creating a login/logout link for my page that dis

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