我想使用 ctype_alpha 通过 textarea 字段提交数据,数据应该完全是字母,没有特殊字符。FALSE
虽然在换行时返回时我如何仍然使用它?
这是 HTML 代码:
<?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');
?>
这是PHP代码:
<?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);
$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.";
}
}
?>