Jump to content

Recommended Posts

Hello

I want to make some login panel with ajax but have no idea where to start. Please let me explain a little what i want to do.

 

When a user type his login name i want to send(onblur()) typed value to db.php and returning value assign to a javascript valiable.

 

My login.php is:

<form name="loginform" id="loginform" method="post" action="">
<table width="300px" class="login" cellpadding="5" cellspacing="2" style="margin:auto;">
	<tr><td align="left" colspan="2"> </td></tr>
	<tr class="row2"><td class="login_lines">username</td>
		<td class="login_lines"><input id="user" type="text" name="user" size="20" onBlur="GotoAjax();" /></td></tr>
	<tr><td class="login_lines">password</td>
		<td class="login_lines"><input id="pass" type="password" name="pass" size="20" /></td></tr>
	<tr><td colspan="2" style="text-align: center"><input type="submit" value="login" class="input-button" /></td></tr>
</table>
</form>

 

And db.php is:

<?php
    include('../inc/cn.php');
    $SQL = mysql_query("SELECT * FROM users WHERE username = '" .$_POST['user']. "'");
    $ROW = mysql_fetch_array($SQL);
?>

 

i want to assign $ROW data into a javascript variable something like this :

login.php

<script language="text/javascript">
   function GotoAjax(){
   // AJAX MAY RUN HERE.
   }
   var id = <?php echo $ROW['id']; ?>;  // Return Value from Ajax query
   var username = <?php echo $ROW['username']; ?>;  // Return Value from Ajax query
   var mail = <?php echo $ROW['mail']; ?>;  // Return Value from Ajax query
...
...
... so on
</script>

 

How can i make this?

 

Regards

Link to comment
https://forums.phpfreaks.com/topic/241760-return-value-to-valiable/
Share on other sites

Okay i solved my problem something like this.

I hope this solution saves someones hours.

 

Regards

 

login.php :

 

<html>
<head>
<script type="text/javascript">
var servername = "";

function showUser(str)
{
	if (str=="")
	{
		return;
	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			servername = xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","check.php?domain="+str,true);
	xmlhttp.send();
}


function craftAction()
{
	document.getElementById("errorspace").innerHTML = '';
	var launch = 1;
	var output = false;

	if(document.loginform.domain.value == '')
	{
		document.getElementById("errorspace").innerHTML += '<font color=#FF0000><?php echo $LOGIN['error1']; ?></font><br />';
		launch = 0;
	}

	if(document.loginform.pass.value == '')
	{
		document.getElementById("errorspace").innerHTML += '<font color=#FF0000><?php echo $LOGIN['error3']; ?></font><br />';
		launch = 0;
	}

	if(document.loginform.user.value == '')
	{
		document.getElementById("errorspace").innerHTML += '<font color=#FF0000><?php echo $LOGIN['error2']; ?></font><br />';
		launch = 0;
	}

	if(launch == 0)
	{
		output = false;
	}
	else{
		var port = document.loginform.port.value;
		var theaction = "https://" + servername + ".winhostings.com:2083/login/"
		document.loginform.action = theaction;
		output = true;
	}

	return output;

}
</script>
</head>

<body>
<form name="loginform" id="loginform" method="post" action="">
<table width="300px" class="login" cellpadding="5" cellspacing="2" style="margin:auto;">
	<tr><td align="left" colspan="2"> </td></tr>
	<tr class="row2"><td class="login_lines">username</td>
		<td class="login_lines"><input id="user" type="text" name="user" size="20" onBlur="showUser(this.value);" /></td></tr>
	<tr><td class="login_lines">password</td>
		<td class="login_lines"><input id="pass" type="password" name="pass" size="20" /></td></tr>
	<tr><td colspan="2" style="text-align: center"><input type="submit" value="login" class="input-button" /></td></tr>
</table>
</form>
</body>
</html>

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.