<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php echo "Homework1_1"?></title>
</head>
<body>
<form action="" method="post">
<input name ="name" type = "text" placeholder="Type your Name">
<input name = "age" type = "text" placeholder = "Type your age">
<input type = "submit">
</form>
<?php
if(isset($_POST["name"])){
$Name =["name"];
$Age = ["age"];
if(preg_match("[0-10]", $name)){
echo "Failed, name can not be number";
}
if(preg_match("/[a-zA-Z + ] +/",$ar)){
echo "Failed, age cannot have letter";
}
if((!preg_match("[0-10]", $Name))&&(!preg_match("/[a-zA-Z + ] +/",$Age))){
echo "Welcome! Your name is $Name and you are $Age years old";
}
}
?>
</body>
</html>
This is my program code. I want if I write number in $Name=["name"] or letter in $Age=["age] the website would show an error message like in the block, but when I run the code and type some values to the both boxes, the website every time shows me
Warning: preg_match() expects parameter 2 to be string, array given in C:\xampp\htdocs\php_workshop_1_citat\GrundOvningar\homework1_1_post.php on line 18
Warning: preg_match() expects parameter 2 to be string, array given in C:\xampp\htdocs\php_workshop_1_citat\GrundOvningar\homework1_1_post.php on line 21
Warning: preg_match() expects parameter 2 to be string, array given in C:\xampp\htdocs\php_workshop_1_citat\GrundOvningar\homework1_1_post.php on line 26
Warning: preg_match() expects parameter 2 to be string, array given in C:\xampp\htdocs\php_workshop_1_citat\GrundOvningar\homework1_1_post.php on line 26
Notice: Array to string conversion in C:\xampp\htdocs\php_workshop_1_citat\GrundOvningar\homework1_1_post.php on line 27
Notice: Array to string conversion in C:\xampp\htdocs\php_workshop_1_citat\GrundOvningar\homework1_1_post.php on line 27
Welcome! Your name is Array, and you are Array years old
What did I do wrong? Maybe I don't need use preg_match? If that is so, what can I do?