/    Sign up×
Community /Pin to ProfileBookmark

Php ajax login problem

Hello,
I have the next error in my code:

[CODE]
<br />
<b>Notice</b>: Undefined index: sLoginUserName in <b>/Applications/XAMPP/xamppfiles/htdocs/KEA/XmlPhp/FriApr17-2015/ajax.php</b> on line <b>7</b><br />
<br />
<b>Notice</b>: Undefined index: sLoginUserPassword in <b>/Applications/XAMPP/xamppfiles/htdocs/KEA/XmlPhp/FriApr17-2015/ajax.php</b> on line <b>9</b><br />
{“status”:”error”}
[/CODE]

I don’t know how to solve it so please help me because I’m totally blocked with this.
My code:
index.php
[url]http://paste.ofcode.org/8apSFyVfNxUCNH2A2VfmDh[/url]

ajax.php
[url]http://paste.ofcode.org/cmXLqgFcnP4gzT3Uq48JMh[/url]

SQL
[url]http://paste.ofcode.org/MJFM2QE8eeHHNwp4qcEkqi[/url]

Host is local host.

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@__flodu__Apr 17.2015 — Hello,

in the index.php try to use this code for the ajax-call: (untested)

<i>
</i>$.get( "ajax.php", { sLoginUserName: sLoginUserName, sLoginUserPassword: sLoginUserPassword} )
.done(function( jData ) {
if(jData.status == "success")
{
$("#wdw-login").hide();
$("#wdw-welcome").show();
$("#lblUserName").text(jData.userName+" and ID : "+jData.id);
}
else
{
$("#wdw-login").effect("shake");
}
});


BTW: this isn't a good idea to build your SQL Query-string: (SQL-Injection, see here)
[code=php]
$sql = "SELECT * FROM customers WHERE user_name = '$sLoginUserName' AND PASSWORD = '$sLoginUserPassword'";
[/code]


For instance you can build the query-string like that:
[code=php]
$sql = sprintf("SELECT * FROM customers WHERE user_name = '%d' AND PASSWORD = '%d';",
$sLoginUserName, $sLoginUserPassword);
[/code]
Copy linkTweet thisAlerts:
@JakubauthorApr 17.2015 — Hello,

in the index.php try to use this code for the ajax-call: (untested)

<i>
</i>$.get( "ajax.php", { sLoginUserName: sLoginUserName, sLoginUserPassword: sLoginUserPassword} )
.done(function( jData ) {
if(jData.status == "success")
{
$("#wdw-login").hide();
$("#wdw-welcome").show();
$("#lblUserName").text(jData.userName+" and ID : "+jData.id);
}
else
{
$("#wdw-login").effect("shake");
}
});


BTW: this isn't a good idea to build your SQL Query-string: (SQL-Injection, see here)
[code=php]
$sql = "SELECT * FROM customers WHERE user_name = '$sLoginUserName' AND PASSWORD = '$sLoginUserPassword'";
[/code]


For instance you can build the query-string like that:
[code=php]
$sql = sprintf("SELECT * FROM customers WHERE user_name = '%d' AND PASSWORD = '%d';",
$sLoginUserName, $sLoginUserPassword);
[/code]
[/QUOTE]


Hi

I tried the code but not work and the same for the sql if I put in the way you gave me the code stop working at all.
Copy linkTweet thisAlerts:
@rootApr 17.2015 — Are you using the very latest XAMPP?

When asking for help, please copy and paste from external sites and wrap code elements in their respective forum tags.

A brief look at your page for your SQL handling, you have some serious security gaps and you should not use $_GET or rather the GET method for loging in, you should always POST to a server, even with Ajax, Use the POST method for sending data like login information.
Copy linkTweet thisAlerts:
@JakubauthorApr 17.2015 — Hi I have the last xampp version and I cannot use post because my professor wants get. For the forum tags I'm sorry bur when I tried to click on the icon for the link it didn't work for some reason.
Are you using the very latest XAMPP?

When asking for help, please copy and paste from external sites and wrap code elements in their respective forum tags.

A brief look at your page for your SQL handling, you have some serious security gaps and you should not use $_GET or rather the GET method for loging in, you should always POST to a server, even with Ajax, Use the POST method for sending data like login information.[/QUOTE]
Copy linkTweet thisAlerts:
@__flodu__Apr 17.2015 — I tested the following code on my own server and it works:
<i>
</i>$(document).ready(function(){
sLoginUserName = "username";
sLoginUserPassword = "password";
$.get( "ajax.php", { sLoginUserName: sLoginUserName, sLoginUserPassword: sLoginUserPassword} )
.done(function( jData ) {
console.log(jData);
});
});



And for the SQL statement, it was my mistake use this:
[code=php]
$sql = sprintf("SELECT * FROM customers WHERE user_name = '%s' AND PASSWORD = '%s';",
mysql_real_escape_string($sLoginUserName), mysql_real_escape_string($sLoginUserPassword));
[/code]
Copy linkTweet thisAlerts:
@JakubauthorApr 17.2015 — Maybe is a problem with my localhost I'll will try on the server because on local host I have issues.

By the way thanks
Copy linkTweet thisAlerts:
@rootApr 17.2015 — Hi I have the last xampp version and I cannot use post because my professor wants get. For the forum tags I'm sorry bur when I tried to click on the icon for the link it didn't work for some reason.[/QUOTE]

You can type the tags out.

Your professor should know that GETting as a way of logging in is a security risk.

If you are using AJAX then theres little point in using AJAX because the point of AJAX is that it is a background process for POSTing and GETting when you want to query a database on the server.
Copy linkTweet thisAlerts:
@JakubauthorApr 18.2015 — The professor told us the opposite about the post and the get. So I don't know, but for now because my project will be evaluated from him I use get.
You can type the tags out.

Your professor should know that GETting as a way of logging in is a security risk.

If you are using AJAX then theres little point in using AJAX because the point of AJAX is that it is a background process for POSTing and GETting when you want to query a database on the server.[/QUOTE]
Copy linkTweet thisAlerts:
@rootApr 20.2015 — POST sends data to the server as a data stream.

GET sends a public URL to a server.

Which one do you think is more readily cache-able?
×

Success!

Help @Jakub spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...