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

Did you know?Explore Trending and Topic pages for more stories like this.
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

Estimations and Effort
HI Gurus,

Would like to know whether SAP have a provision for carrying out the Project es

Seperate team from score
I am writing a site that does a NFL Pick 'em type application and I have a feed that gives me the sc

Multiple Options for a Single Page
For this example I want to use the Handlers option which is under Fed Admin and all the related codi

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

Upload file!
Ok i have a form..
Code: <form name="form1" method="post" action=&quo

Please help with code for SMTP authenticated PHP email form
Hello, I'm creating a PHP email form, and for this particular server, I have to use SMTP Authenticat

login page does not execute a else statement
I've created a login page using sessions.
When an incorrect user name or password is entered then

Strip Slashes Help
I've got a script that i've downloaded of the net to edit multiple fields from my sql database, and

Remove letter from numeric textbox
I have a textbox that will search the employee database by entering in the employee ID and it will r

very easy question about SQL info
Hello,
I think that I have a very easy question.
I know how to create a form using php SQL and

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