Jump to content

Log In Using Php Lightbox Javascript


Recommended Posts

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">


<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";



body {

background: url(../Images/Bgcolor.jpg);

background-size: 100%;

background-position: top center;

background-repeat: no-repeat;




<script type="text/javascript" src="JQuery.js"></script>

<script type="text/javascript" src="Dialog/jquery.lightbox_me.js"></script>



function ShowLogin(){

$f_usr = $_POST["username"];

$f_pswd = $_POST["password"];



if(! $con){

die('Connection Failed'.mysql_error());




$result = mysql_query("SELECT * FROM client WHERE username= '" .$f_usr. "' AND password= '" .$f_pswd. "' ");



if ($numrows != 0){

header("Location: Homepage.php");}








<script type="text/javascript">

function ShowRegistration(){



















<form name="frm" action="Registration.php" method="post">


<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"


WIDTH="640" HEIGHT="480" id="RYNC" ALIGN="">


<PARAM NAME=quality VALUE=high>


<EMBED src="../Flash/RYNC.swf" quality=high bgcolor=#FFFFFF WIDTH="640" HEIGHT="480" NAME="RYNC" ALIGN="" TYPE="application/x-shockwave-flash"






<input type="text" value="" name="username">



<input type="password" value="" name="password">



<input type="button" value="Log In" name="Login" onclick="<? ShowLogin(); ?>">

<input type="button" value="Register now" name="Register" onclick="ShowRegistration();">

<div id="descDialog"></div>




Thanks in advance




Edited by ChrisPHP
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.