How to show the existing username in a database with jQuery AJAX?

1

You could say that I am "new" in this php language and mysql queries, since you are developing a website, practically Social Network, which is centralized in hosting photos by users, that is, each registered user has the opportunity to upload your photos, create albums, etc. I say this in case the way in which I try to do these functions for this page are not the appropriate ones or they are not the most recommendable and they can let me know, since the problem as such that I have is that I know how to do it with jQuery and AJAX can display the newly registered user name and also logged in.

In this case I am only using the registration area that when the user registers, access this area of the login, but I have tried some php queries, but that would imply that I had to place the php code on the same page of the login so that when reloading, that variable with its name is defined, since if I do it from an external php file, when inserting that variable in the login page it will tell me that it is undefined, therefore I decided to use jQuery and AJAX to this, the code with which I am trying to do it is an example, a test project, because I do not like to experiment in my project as such ...

var usuario = $('#user');
var envio = $('#send');

envio.click(function(e){
	if (usuario.val()[0] !== '@') {
		e.preventDefault();
	alert("El nombre de usuario siempre empieza con '@'");
	}
	else{
		nUser = usuario.val();
		$.ajax({
			url:'Mostrar.php',
			data:{nUser},
			type:'POST',
			success: function(response){
				var tarea = JSON.parse(response);

				tarea.forEach(tarea =>{
					console.log(task);
				})
			}
		})
	}
})
    
asked by Abdiel 22.11.2018 в 17:45
source

1 answer

0

Hello how are you? If you want to do it on the same page, it's wrong. What I would recommend is to send an alert as a sweet alert to the user who registered and show him the username in the alert. If you are looking for a newly registered user to be redirected to the login screen with the user already registered by AJAX it is not possible, given that this api only works in real time and in the same PHP file.

Another recommendation is to save the user name just registered in SESSION and when loading the login apply it to the username input and then destroy the SESSION.

    
answered by 22.11.2018 / 18:09
source