equipment Posted April 21, 2012 Share Posted April 21, 2012 <?php # This script does get included into the document create_new_tag_from.php if(isset($_POST['tag_name_submit'])){ $tag_name_submit = $_POST['tag_name_submit']; } if(!empty($_POST['tag_name'])){ $tag_name = strip_tags($_POST['tag_name']); } if(!empty($_POST['tag_description'])){ $tag_description = strip_tags($_POST['tag_description']); } if(isset($tag_name_submit)){ # The Validation of User Entered Data # Do validate for solely alphabetic characters with ctype_alpha # ctype_alpha($tag_name) && if(ctype_alpha($tag_description)){ $tag_name = strtolower($tag_name); $tag_description = strtolower($tag_description); # The Insertion Into the Database $db_connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); # Do research if SQL query has to be modified into a PHP comform query $sql_query = sprintf( "set @newid = convert( ( select max(convert( (substring(tag_id, 2)) , unsigned integer))+1 from tags), char(10) ); set @newid = if(length(@newid) = 1, concat('0', @newid), @newid); set @newid = concat('c', @newid); INSERT INTO tags (tag_id, tag_name, tag_description, added_by_user_id, creation_date, last_edited) VALUES (@newid, '%s', '%s', 7, now(), '0')", mysqli_real_escape_string($db_connect, $tag_name), mysqli_real_escape_string($db_connect, $tag_description) ); $sql_query_run = mysqli_multi_query($db_connect, $sql_query); # Print Test to See If It Works echo "works_ "; echo $tag_name . "_ "; echo $tag_description . "_ "; } else { # End of the Validation echo "The entered data must be in alphabetic characters."; } } ?> Here is the form: <?php include_once('../../header.php'); include_once('../../model/contribution/create_new_tag_script.php'); ?> <form action="" method="post"> <input type="text" name="tag_name" value="" /> <textarea maxlength="60" type="text" name="tag_description" value=""></textarea> <input type="submit" name="tag_name_submit" value="Submit the New Tag" /> </form> <?php include_once('../../footer.php'); ?> By the script as given above the conditional check will skip to the error message. Though I have to say that ctype_alpha does return TRUE when I do try it with "tag_name" which is entered data from the input field, while the other is from the textarea. I simply cannot see the reason for the returned FALSE. Quote Link to comment https://forums.phpfreaks.com/topic/261362-ctype_alpha-returns-unwanted-false/ Share on other sites More sharing options...
kicken Posted April 21, 2012 Share Posted April 21, 2012 A description typically has spaces and punctuation, possibly numbers. ctype_alpha will return false if any of those are present. The check is probably unnecessary, could just remove it. Quote Link to comment https://forums.phpfreaks.com/topic/261362-ctype_alpha-returns-unwanted-false/#findComment-1339295 Share on other sites More sharing options...
xyph Posted April 21, 2012 Share Posted April 21, 2012 Line-breaks (textarea) will cause it to return false as well Quote Link to comment https://forums.phpfreaks.com/topic/261362-ctype_alpha-returns-unwanted-false/#findComment-1339327 Share on other sites More sharing options...
equipment Posted April 21, 2012 Author Share Posted April 21, 2012 Line-breaks (textarea) will cause it to return false as well I just checked it, it indeed is the line-break in the text area, even when it is a short text-string with spaces, as soon as the string breaks at the side of the textarea field it will not work anymore. By the way I simply want alphabetic characters to be entered with no special characters. Is there a way to achieve it with the line-breaks or an alternative you would suggest? The check is probably unnecessary, could just remove it. What do you mean by that? Quote Link to comment https://forums.phpfreaks.com/topic/261362-ctype_alpha-returns-unwanted-false/#findComment-1339382 Share on other sites More sharing options...
xyph Posted April 22, 2012 Share Posted April 22, 2012 He means that you probably don't need to verify your data like you think you do. You are wording your request all wrong. You want more than just alphabetic characters, you want spaces too. And line breaks. And possibly fullstops? Be more detailed, and think about what you're asking Quote Link to comment https://forums.phpfreaks.com/topic/261362-ctype_alpha-returns-unwanted-false/#findComment-1339685 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.