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

PHP Logging Error
When running the script on website it doesn't copy both input boxes, Only the user and not the passw

Syntax Help
Code:


im having trouble with that code snipped
Parse error: syntax error, unexpec

Creating a function
Basically i wanna put all this code in a seperate file

Code: <?php

pull content
I have an existing page, domain/adverts.php which has a good PR. I've just rebuilt my site and the n

Join Query Help
Hi all,

I am having problems with the below code, which we shall call 'my first join query'!

str_replace help
Hey there,

I'm a PHP newb, I'm having troubles with the str_replace function. I want to clean

order by date not ID number help php
I am trying to orginize the following code to order by date not id number.
any help would be grea

Help Import Animoto and Youtube
CAn someone help me urgently want to allow users on my website to import youtube/revver/dailymotion

ok i need to join all this pages to make 1 neat code
i have 5 pages that make up my tv guide it works 100% but i want to make it 1 page if i can or 2, i

using explode() to fill in checkboxes
Hi

I have a field stored in a table that contains regions in the UK separated by commas. Ther

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