Jquery/PHP process/valid/redirect login Help.

I have a user registration form and I’m trying to process and redirect the page to the “logged-in-user”(if info matches info in db and create sessions) it using jquery and php, but it isn’t working/I don’t understand how to do something/ Or is this possible. If the Username Field and or the Password Field are empty I want to show an error and not process it.
Heres my code.
js/jfunc.js

[code]$(document).ready(function() {
$(’#errors’).hide();

$(’#loginform’).submit(function() {

//when form is submitted
var user = $(’#user’).val();
var pass = $(’#pass’).val();

if ((user) == ‘’ || (pass) == ‘’){

$(’#errors’).html(“The username and the assword are required fields !”).fadeIn(500);
return false; // notice this !, this very important !

}else
$.post(‘includes/usercheck.php’,
{php_user: user, php_pass: pass}
,function(data){

           });


        });  

});
[/code]
usercheck.php
[php]

<?php $php_user = $_POST['user']; $php_pass = $_POST['pass']; if ($php_user&&$php_pass) { $connect = mysql_connect("localhost", "root", "password") or die(mysql_error()); mysql_select_db("logintest") or die(mysql_error()); $query = mysql_query("SELECT * FROM users WHERE `password`='$php_pass' && `email`='$php_user'"); $numrows = mysql_num_rows($query); if ($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { //create session variables $_SESSION['firstname'] = $row['first_name']; //All of the session creation info goes here $_SESSION['user_id'] = $row['user_id']; $php_user = $row['username']; $_SESSION['username']=$php_user; header('Location:main.php') } } } ?>

Parsed in 0.162 seconds, using GeSHi 1.0.8.4
[/php]

This is my login check code

[php]

<?PHP include("database.php"); $link = connect(); $username = strip_tags($_GET['username']); $password = strip_tags($_GET['password']); $sql="SELECT * FROM trade.user WHERE username='".strip_tags($username)."' AND password=MD5('".strip_tags($password)."')"; $db = "trade"; if(! $res = send_sql($sql, $link, $db)) { echo "Database problem"; exit; } if(mysql_num_rows($res) == 0) echo "fail"; else { session_start(); $arr = mysql_fetch_row($res); $_SESSION["p_id"]= $arr[0]; $_SESSION["user"]= $arr[11]; if(isset($_SESSION["destination"])) echo $_SESSION["destination"]; } ?>

[/php]

and this is my java code with the login form
[php]

<?php session_start(); ?>






Sign in to your account













Your User ID or Password is incorrect.

Username:

Password:



I forgot my User Id or Password



[/php]

Its simple and works

Sponsor our Newsletter | Privacy Policy | Terms of Service