mike12255 Posted July 19, 2009 Share Posted July 19, 2009 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 More sharing options...
Bendude14 Posted July 19, 2009 Share Posted July 19, 2009 try using if(isset($_POST['login'])){} instead of if($_POST['submit']) and use isset() on you logincheck as well. Ben Link to comment https://forums.phpfreaks.com/topic/166468-function-not-doing-what-i-want/#findComment-877826 Share on other sites More sharing options...
mike12255 Posted July 19, 2009 Author Share Posted July 19, 2009 didnt work, thanks though Link to comment https://forums.phpfreaks.com/topic/166468-function-not-doing-what-i-want/#findComment-877829 Share on other sites More sharing options...
Bendude14 Posted July 19, 2009 Share Posted July 19, 2009 post your new code so I can see what you changed... Link to comment https://forums.phpfreaks.com/topic/166468-function-not-doing-what-i-want/#findComment-877834 Share on other sites More sharing options...
9three Posted July 19, 2009 Share Posted July 19, 2009 <?php if (!$logincheck) { echo $logincheck; } ?> Edit: You might have to change it around a little else{ echo "Sorry bad username/password comination"; return false; } Link to comment https://forums.phpfreaks.com/topic/166468-function-not-doing-what-i-want/#findComment-877835 Share on other sites More sharing options...
mike12255 Posted July 19, 2009 Author Share Posted July 19, 2009 tried your change and still not working anyone else have an idea? Link to comment https://forums.phpfreaks.com/topic/166468-function-not-doing-what-i-want/#findComment-878052 Share on other sites More sharing options...
mike12255 Posted July 20, 2009 Author Share Posted July 20, 2009 any ideas on how to get this working? Link to comment https://forums.phpfreaks.com/topic/166468-function-not-doing-what-i-want/#findComment-878342 Share on other sites More sharing options...
mike12255 Posted July 20, 2009 Author Share Posted July 20, 2009 bump ;P Link to comment https://forums.phpfreaks.com/topic/166468-function-not-doing-what-i-want/#findComment-878389 Share on other sites More sharing options...
Bendude14 Posted July 21, 2009 Share Posted July 21, 2009 I repeat...post your new code so I can see what you changed... Link to comment https://forums.phpfreaks.com/topic/166468-function-not-doing-what-i-want/#findComment-879327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.