Jump to content

ctype_alpha Returns Unwanted False


equipment

Recommended Posts

<?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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.