Jump to content

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

<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 by ChrisPHP
Link to comment
https://forums.phpfreaks.com/topic/271783-log-in-using-php-lightbox-javascript/
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.

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

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.

Guest
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.