javascript - Error when running external php mysql query through JQuery -
hey using jquery call file 'login.php
'. when click log in on pop modal error
access denied user 'urbanas8'@'localhost' (using password: no)
when know connection database correct , works other pages not call external php files. don't understand why error occurring maybe 1 of guys can tell me whats going on here?
login modal
<!--login modal --> <?php require_once( "./inc/connect.inc.php" ); ?> <div class="modal fade col-sm-4 col-sm-offset-4" id="login" role="dialogue"> <div class="modal-dialogue"> <div class="modal-content"> <form action="" method="post"> <div class="modal-header"> <h4>login</h4> </div> <div class="modal-body row"> <div class="form-group"> <div class="col-sm-12"> <input type="text" class="form-control" id="username" placeholder="email address"> </div> <div class="col-sm-12"> <input type="password" class="form-control" id="userpassword" placeholder="password"> </div> <!-- end address form --> </div> </div> <div class="modal-footer"> <button type="button" class = "btn btn-warning" id="loginbutton" value="login" name="/login">login</button><a class = "btn btn-warning" data-dismiss = "modal">cancel</a> </div> </form> <script> $(document).ready(function(){ $("#loginbutton").click(function(){ console.log("test123"); var username = $("#username").val(); var password = $("#userpassword").val(); $.post("../login.php", {login:username, password:password}, function(data){ console.log(data); }); }); }); </script> </div> </div> </div>
login.php
<?php if(isset($_post['login'])){ echo "<br>login set<br>"; $user_login = strip_tags($_post['login']); echo $user_login."<br>"; $password_login = strip_tags($_post['password']); echo $password_login."<br>"; $password_login = md5($password_login); echo $password_login."<br>"; $sql = mysql_query("select * users email='$user_login' , password='$password_login' limit 1") or die(mysql_error()); $usercount = mysql_num_rows($sql); echo $usercount."<br>"; if($usercount == 1){ while($row = mysql_fetch_array($sql)){ $user_id = $row["id"]; $user_fname = $row["first_name"]; $user_lname = $row["last_name"]; $user_membersince = $row["date"]; } $_session['user_email'] = $user_login; $_session['user_fname'] = $user_fname; $_session['user_lname'] = $user_lname; $_session['user_membersince'] = $user_membersince; echo("logged in!"); }else { echo("invalid username/password"); } } ?>
connection.inc.php
<?php $db = mysql_connect("localhost:3306", "urbanas8_login", "ure1982*") or die(mysql_error); mysql_select_db('urbanas8_db', $db) or die(mysql_error()); ?>
there problem in username through logging mysql. error message shows username 'urbanas8' connection file shows 'urbanas8_login'.
you have not included file "connection.inc.php" in login.php
i recommend use mysqli instead of mysql. deprecated.
<?php //conection: $link = mysqli_connect("myhost","myuser","mypassw","mybd") or die("error " . mysqli_error($link)); //consultation: $query = "select name mytable" or die("error in consult.." . mysqli_error($link)); //execute query. $result = $link->query($query); //display information: while($row = mysqli_fetch_array($result)) { echo $row["name"] . "<br>"; } ?>
Comments
Post a Comment