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

$GPRMC and NMEA how to extract from report
Hi There,

Im a little bi lost and not sure where to start with this one, ive got a small gps

User input in to variable
Hi all,

I'm sure this is very easy but I'm having another brain freeze!

At the end of

ereg_replace()
Basically what i need to do is

$title = "This Suck's"

$striped = ereg_repl

help retrieiving results and doing pagination
Having some trouble trying to get the results to show on more than just one page.

What is ha

rookie looking for help coding a CSS form with PHP
I'm trying to figure out how to add PHP code to my xhtml form so that it is a working form embedded

MS are the best!!!
Visit http://www.microsoft.com/australia/windows/default.aspx?h=watch-a-demo and click the massive '

add to sql result
ok see rite now my sites hit counter is counted from the mysql visitor log i need to clear it aft

Firefox displaying PHP source code??
Currently testing a site thats almost built, am going to be including php on a sidebar on all pages

Sharing PHP Sessions Across Domains
I am in the process of writing a script to share a php session across various domains I have.
The

include function being weird?
I have a very simple system to grab an IP outputted by a PHP file.. (for a project I have) but it ou

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