Jump to content

login script help


haruncpi
 Share

Recommended Posts

I have a login function in my site.I have used

if($count==1){$row = mysql_fetch_array($result); print ("login success");}else{print ("wrong!");}

I wanna if the If condition true it will give a success msg and redirect the previous page. Else it will show a login wrong message with javascript alert box with ok button. How can i do it? please help me anybody.......

Link to comment
Share on other sites

You can use the header function to send a location header to redirect the user, but if you do that you can't output any message first. If you want to show a page and redirect after a few seconds then you output a regular HTML page with your message on it and use either a meta tag or some Javascript code to do the refresh after a certain time. If you search for those terms you'll find the information about how to use them. The case if they are wrong is the same, just output a regular HTML page with whatever Javascript code you want to show the alert.

Link to comment
Share on other sites

You can use the header function to send a location header to redirect the user, but if you do that you can't output any message first. If you want to show a page and redirect after a few seconds then you output a regular HTML page with your message on it and use either a meta tag or some Javascript code to do the refresh after a certain time. If you search for those terms you'll find the information about how to use them. The case if they are wrong is the same, just output a regular HTML page with whatever Javascript code you want to show the alert.
Tnx for quick response. Actually i wanna if the if condition false it will give a alert box in same page i mean login.php page.
Link to comment
Share on other sites

So then output the Javascript code to make it do that. Instead of printing "wrong", print the Javascript code. If the code you showed is on a different page then you're talking about submitting the form using ajax and handling the response with Javascript.

Link to comment
Share on other sites

So then output the Javascript code to make it do that. Instead of printing "wrong", print the Javascript code. If the code you showed is on a different page then you're talking about submitting the form using ajax and handling the response with Javascript.
Would you give me an example please?
Link to comment
Share on other sites

Start with the ajax tutorial if that's the path you want to take: http://www.w3schools.com/ajax/default.asp With ajax, you would write a Javascript function to handle the form submission and the function would get the username and password, send it to PHP, read the response from PHP, and do whatever else you want to happen on the login page. Ajax is the technique for sending normal browser requests to your server without needing to refresh the whole page.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...