Jump to content

Login using functions and minimal php in design file.


Eggzorcist

Recommended Posts

I've been trying to create an application which has hardly any php within the design files and a large core function files.

 

I'm trying to create a login however it seems like it isn't working...

 

I think my problem is in the design php file, though I will also attach my function that I've created.

 

 

login_user function

function login_user($username, $password){

$username1 = secure_var($username);
$password1 = md5(secure_var($password));


if ($username != NULL and $password != NULL){

	$login_query = mysql_query("SELECT * FROM user_info WHERE username = {$username1} AND password = {$password1}");

	$login_status = mysql_num_rows($login_query);


	if($login_status == 1){
		echo "good";

	set_login_sessions($username, $password);


}

}

else {

echo "Please enter a Username and Password";	

}

 

That includes a config.php file also...

 

 

design file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>One Project Organizer </title>
<link rel="stylesheet" type="text/css" href="onestylesheet.css"/>
</head>

<?

require('functions.php');


?>

<body>
<div id="onewrap">
<div id="oneheader">
<div class="oneheadertext">One Project Organizer</div>
</div>
<div id="onesubheader">Log-in</div>
<div class="oneerror"></div>
<div class="onecontent"><form id="form1" name="form1" method="post" action="">
    <label>Username:
       <input type="text" name="username" id="username" />
    </label>
    Password: 
    <label>
      <input type="password" name="password" id="password" />
    </label> <input type='button' onclick="<?php login_user($_POST['username'], $_POST['password']); ?>" value="Login"/>
</form>
</div>




</div>
</body>
</html>

 

 

Thanks for any help! :D

 

Link to comment
Share on other sites

first thing that i noticed...

 

      $login_query = mysql_query("SELECT * FROM user_info WHERE username = {$username1} AND password = {$password1}");

 

replace the curly brackets with quotes, cause they are chars, varchars, or strings of some sort

 

      $login_query = mysql_query("SELECT * FROM user_info WHERE username = '$username1' AND password = '$password1'");

Link to comment
Share on other sites

The method I used to use was the isset($_POST['submit']), I know this is a possibility but it gets more messy with php in the design files, is there  very clean way of doing it, because obviously the way I did it above isn't working.

Link to comment
Share on other sites

I added a checkpoint echo to see if the function was actually being used, and it seems like the function being called isn't making the function work. Am I doing something wrong?  also changed a few things. But doesnt seem to make the function work or even being used either...

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>One Project Organizer </title>
<link rel="stylesheet" type="text/css" href="onestylesheet.css"/>
</head>
<?php include('functions.php'); ?>
<?php if(isset($_POST['login'])){ login_user($_POST['username'], $_POST['password']);}?>
<body>
<div id="onewrap">
<div id="oneheader">
<div class="oneheadertext">One Project Organizer</div>
</div>
<div id="onesubheader">Log-in</div>
<div class="oneerror"><?php echo $errormessage; ?></div>
<div class="onecontent"><form id="form1" name="form1" method="post" action="">
    <label>Username:
       <input type="text" name="username" id="username" />
    </label>
    Password: 
    <label>
      <input type="password" name="password" id="password" />
    </label> <input name="Login" type='button' id="login" value="Login"/>
</form>
</div>




</div>
</body>
</html>

 

thanks

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.

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.