Y
Y
Yanimax2018-03-23 13:51:22
PHP
Yanimax, 2018-03-23 13:51:22

How to display error handling function $erros = array(); in Alert?

Good day to all.
I have code:

if(isset($_POST[send_reg]))
{
$check_isset_login = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `login` LIKE '".$_POST[login]."'"));   
$erros = array();
if($check_isset_login > 0){array_push($erros, 'Login is busy');}
if(empty($_POST[login])){array_push($erros, 'Неверный логин');}
if(empty($_POST[password])){array_push($erros, 'Password is not filled');}
if(empty($_POST[repassword])){array_push($erros, 'Re-Password is not filled');}
if(empty($_POST[email])){array_push($erros, 'Email is not filled');}
if(!preg_match("/[a-zA-Z]/",$_POST[login])){array_push($erros, 'login entered incorrectly');}
if($_POST[password] != $_POST[repassword]){array_push($erros, 'Passwords do not match');}
if(!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",$_POST[email])){array_push($erros, 'EMail entered incorrectly');}
if ($erros === Array())

This is how it looks now:
5ab4dbb997d05555328118.png
Please tell me why the errors are displayed incorrectly?
I am a complete zero in php, I just had a question to fix this problem on my old site.
Here's a screenshot of how it's happening now. I display errors not with ajax, but when submitting the form.
Thanks to everyone who answers the question.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Gorelov, 2018-03-23
@Kirill-Gorelov

You have somewhere print_r() или var_dump(), so you have an array entered.
If you want to display this array in js via alert, then you can do this.

//php код
$erros = implode(','$erros);

//js код
var obj = '<?=$erros;?>';
var arr = obj.split(',');
alert( 'Ваши ошибки ' + obj);

Something like this.
But it's better not to alert, but simply to display somewhere on the page.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question