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

AJAX form submit
I recently built a form that submits data to my database with an ajax function that is called throug

Calander layout
Hi i know this sounds like a simple question but i cant find the answer to it anywhere i have added

Insert Failing.
Hey,
I am making a Sign up page for a website, but the insert query into the Database does not se

array_combine() trouble w/csv file
I have a problem with a piece of code I wrote to import some records from a csv file into mysql. I h

problem when runing a funciton
I am trying to connect to database using a funciton in a functions.php

<?php
funct

Email logic not working
I would like to send an email using the php email() function then if it does execute i.e sends i wou

how to transport the Query and insfoset
Hi

I have created the query using SQ01........
How to created T-code for query..

Baffled by Undefined Index in Simple Array: Please Help!
Hello. I have a form which posts an array to this script. However, I can't seem to access the values

regex for quoted text within a string
I am still getting the hang of regex expressions, but I cant seem to figure out how I would escape q

bind error during socket programming
i am kinda new to socket programming. wrote the below code for a server. but getting the bind error

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