ChrisPHP Posted December 9, 2012 Share Posted December 9, 2012 (edited) Hello everyone, I have this idea for a website that I can't seem to solve. I created an intro page where there's a username and a password to type and two buttons, a login button and a register button. What I wanted to do is when the login button is pressed it compares the username and the password with database entries, if they're available, it would redirect the client to homepage. If not, the lightbox would appear for registration. The code to my intro page is: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title> RYNC - Rent Your Car Now</title> <style type="text/css"> @import "Dialog/DescriptionDialog.css"; @import "Dialog/styles.css"; </style> <style> body { background: url(../Images/Bgcolor.jpg); background-size: 100%; background-position: top center; background-repeat: no-repeat; } </style> </script> <script type="text/javascript" src="JQuery.js"></script> <script type="text/javascript" src="Dialog/jquery.lightbox_me.js"></script> <?php function ShowLogin(){ $f_usr = $_POST["username"]; $f_pswd = $_POST["password"]; $con=mysql_connect("localhost","root",""); if(! $con){ die('Connection Failed'.mysql_error()); } mysql_select_db("projet",$con); $result = mysql_query("SELECT * FROM client WHERE username= '" .$f_usr. "' AND password= '" .$f_pswd. "' "); $numrows=mysql_num_rows($result); if ($numrows != 0){ header("Location: Homepage.php");} else{ ShowRegistration();} } ?> <script type="text/javascript"> function ShowRegistration(){ .get("Registration.php", function(data){ $("#descDialog").empty(); $("#descDialog").append(data); $("#descDialog").lightbox_me({ centered:true }); }) } </script> </head> <body> <form name="frm" action="Registration.php" method="post"> <center> <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="640" HEIGHT="480" id="RYNC" ALIGN=""> <PARAM NAME=movie VALUE="RYNC.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="../Flash/RYNC.swf" quality=high bgcolor=#FFFFFF WIDTH="640" HEIGHT="480" NAME="RYNC" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED> </OBJECT> <br> Username <input type="text" value="" name="username"> <br> Password <input type="password" value="" name="password"> <br> </form> <input type="button" value="Log In" name="Login" onclick="<? ShowLogin(); ?>"> <input type="button" value="Register now" name="Register" onclick="ShowRegistration();"> <div id="descDialog"></div> </body> </html> Thanks in advance Regards, Chris Edited December 9, 2012 by ChrisPHP Quote Link to comment https://forums.phpfreaks.com/topic/271783-log-in-using-php-lightbox-javascript/ Share on other sites More sharing options...
Muddy_Funster Posted December 10, 2012 Share Posted December 10, 2012 PHP is server side, it's run on the server, before it gets to the browser. Javascript is client side, it's run on the client machine and interacts directly with the browser. PHP can't call a javascript function because the function is on a page that hasn't been written at the time PHP is running. You would probably be best using an AJAX call to check the login and using a javascript window.location = on success. this will let you still use php for validation and should enable you to call your lighbox script on failure. On another note - I don't think auto loading the registration form on a failed login atempt is at all user friendly - people make mistakes with logins all the time, I know I'd be frustrated if I constantly got redirected to a registration form every time I done it, but most can tell the difference, when clearly presented with the options, between logging in and registering. Quote Link to comment https://forums.phpfreaks.com/topic/271783-log-in-using-php-lightbox-javascript/#findComment-1398508 Share on other sites More sharing options...
ChrisPHP Posted December 11, 2012 Author Share Posted December 11, 2012 Thank you so much for replying, your post did help me a lot. I've been frustrated for days with this issue. I knew that I couldn't call a PHP function but didn't know what I actually should do. I'll probably look up this window.loction= thing and try to use in the website!! Quote Link to comment https://forums.phpfreaks.com/topic/271783-log-in-using-php-lightbox-javascript/#findComment-1398629 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.