Jump to content

function not doing what I want


mike12255

Recommended Posts

I want this function to either log the user in or return the string $error telling the user they entered wrong info here is my code:

 

index.php

 

<?php

include "universal.php";

if($_POST['submit']){
$logincheck = user_login($_POST['username'],$_POST['pwd']);
}


?>


<!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>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #999999;
}

#box{
border:2px #000000;
background-color:#CCCCCC;
width:400px;
height:300px;

}
-->
</style></head>

<body>
<div id="box">
<form method="post"  action="index.php">
                <p align="center"><span class="style1 style12 style20">Username: </span> 
                  <input type="text" name="username">
                  <br>
                   <p align="center"><span class="style1 style12 style20">Password: </span> 
                  <input type="password" name="pwd">
                  <br>
                  <input type="submit" name="login" value="Login">
                </p>
              </form><br />
<br />
<?php
if ($logincheck) {
echo $logincheck;
}


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

 

 

universal.php:

 

<?php
//These are required on all pages so make sure they get called as soon as file is included
session_start();
include ("connect.php");


function user_login ($user,$pass){
$user = mysql_real_escape_string($user);
$pass = mysql_real_escape_string($pass);
$sql = "SELECT * FROM tbl_users WHERE username = '".$user."'AND password = '".$pass."'";
$res = mysql_query($sql) or die (mysql_error());

if (mysql_num_rows($res) > 0){
$_SESSION['user'] = $user;
header ("Location: editpages.php");

}else{
$error = "Sorry bad username/password comination";
return $error;
}
}// end of login function
?>

 

 

can anyone help me make the string appear on the index pagee when info is not found?

Link to comment
https://forums.phpfreaks.com/topic/166468-function-not-doing-what-i-want/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.