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){
$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
14
Other forums
Database/Table Collation
What is the Database, and table collations used for? i don't understand what there used for since co
Coding question?
Hey guys, I have a quick question. If I want to make a way for people to pay for health in my game,
Polymorphism
Was wondering if someone could explain this a little better to me. I had always assumed that it had
Hyperlink in PHP to MySQL record
Hello,
I am having trouble as i am new to php. I have connected to the database and I have di
Recode Abap Dynpro into Web Dynpro
Hi All,
A client has asked us to look at rearchitecting a custom transaction that was developed
Apple's revamped lineup arrives
I'm personally curious about the magic mouse.. a multi-touch concept sounds like it could be nea
MySQL Does not UPDATE- SQLString Problem
vb Syntax (Toggle Plain Text)
1.
SQL = "UPDATE sampletable SET column1 = 'C1sample1'"
how to timeout $doc = new DOMDocument()->load($url)
I am currently using this $doc->load($url) to fetch an rss feed.
If a feed takes long than
New Search Engine problem
Hey everyone,
I have a ZIP Code Radius search engine already functional. it displays all of t
Format String help
I have a textbox where a person enters an application number. the application number is 10 characte