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
14
Other forums
Limiting checkboxes?
Hi guys,
I have this code: Code: if(isset($_POST['selected'])) {
foreach($_POST['selec
PHP Redirecting
Hello everyone. Is there a way to redirect people to pages within a statement in PHP? Since there is
COde for a Cc
I'm not receiving $ft as a Cc. Why is that??
$to = "$email";
$headers = "Fr
subtract 1 from value entered in text field
Hi
How do I subtract 1 from the vaue entered into a text field?
Thanks
Easy administration on MySQL databases
My website is database driven and I am very tired of manually making queries to my tables in order t
At max how many columns is advisable to create in a table/view
Hi All,
I have two transaction table from which i want to create a simple view or material
New Login Script
Hi all, i attempted to create a whole new login script witch isnt working for some reason i dont kno
Weird Problem with curl while sending data
I am facing a weird problem with sending data to a site via curl.
If i send the value by this
simple script won't work. Please help
I'm new to php, and I am having trouble displaying a simple script in my web browser. My php code ex
Images in email problem
I found this script for sending emails, it works but if the email has <img src="image.jp