Why is this function returning a false value when it shouldn't be??


Posted on 16th Feb 2014 07:03 pm by admin

This is in an include file. I want it to check a value in an html form and see if it's just white space, is numbers, is empty etc.

Code: (text) [Select]<?php
function checkString($stringFieldName,$_GET){
Did you know?Explore Trending and Topic pages for more stories like this.
$output="n<p> ";
$validate=true;
if(array_key_exists($stringFieldName,$_GET))
{
//trim any whitespace from values
$string=trim($_GET[$stringFieldName]);
//check if string value is empty
if(empty($string)){
$output.="nYou haven't entered any data in string<br />";
$validate=false;
}
if(is_numeric($string)){
$validate=false;
$output.="You have entered a number instead of text";
}
//if they have deleted values from url
}else{
$output.="nYou have deleted the characters from the urln";
$validate=false;
}
echo $output."n</p>";
}
I am using it in a php file, the code is here:
Code: (text) [Select]
<?php
echo "n<p>";
include 'validateText&Number.inc';
checkString("surname",$_GET);
if ($validate==false){
echo "nYou did not enter the name correctly.";
}
else.................
{When I type in actual text it tells me I have not entered name correctly which therefore means $validate must be false. I don't know how though it can be set to false because if the field just contains text, it isn't satisfying any of the conditions that lead to $validate=false.

Please help!! Oh I'm a php newbie btw
No comments posted yet

Your Answer:

Login to answer
251 Like 14 Dislike
Previous forums Next forums
Other forums

Multi image upload
I have a gallery to build and want to build a dynamic upload form to allow for $var number of fields

column name cancatenation within PL/SQL
I have a PLSQL store procedure, and the following statement is part of a subquery
fname||lnam

using a loop help
Hi guys , i need some help. I have this loop :
while ($row = mysql_fetch_assoc($Result)) { ?&

Php - mysql store data and use it later?
Hi, i' making a login page at the moment, however my username + password is stored many different pl

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

Must be a string? Huh, what? HELP?
with the following script, I get
Fatal error: Property name must be a string in /home/content/e/

Unique Visitor Tracking
Hello. Currently, I run a voting site where voters are tracked by their IP address and can only vote

Add a sign-up feature to a flat file login script
I'm working on a flat file login script and I would like to add a sign-up feature to it with a email

Taking an HTML form and a PHP program and making it into one working file.
Hello,

So I would like to display everything INSIDE a specific directory. In other words, I

need good snippet manager
Hi. as i am coding and learning more, it is becoming difficult to manage code snippets. how you mana

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