mike12255 Posted July 18, 2009 Share Posted July 18, 2009 here is my index.php file <?php include "universal.php"; if($_POST['submit']){ 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 ($error){ echo $error; } ?> </div> </body> </html> and here is my univeral.php file: <?php /* ********************************************* ********UNIVERAL CMS FUNCTIONS*************** ********FOR STUDENT WEB PRO****************** ********DEVELOPED BY: MICHAEL H************** ******* JULY 18 2009************************ ********************************************* */ //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,$error){ $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 //MAKE SURE ADMIN IS LOGGED ON ON ADMIN PAGES function check_status($session){ if ($_SESSION['user']){ return true; }else{ return false; } } //CREATE THE BOX function create_box($page){ $sql = "SELECT * FROM tbl_pages WHERE page = '".$page."'"; $res = mysql_query($sql) or die (mysql_error()); while ($row = mysql_fetch_assoc($res)){ $info=$row['info']; } echo "<form method=\"post\" action=\"edit.php?page= . '$page' .\">"; echo "<div>"; echo "<p>Design exactly how you want the Wine page to look in this: click submit when finished.</p>"; echo "<div>"; echo "<textarea id=\"info\" name=\"info\" rows=\"15\" cols=\"70\" style=\"width: 80%\">"; echo $info; echo "</textarea>"; echo "</div>"; echo "<input type=\"submit\" name=\"save\" value=\"Submit\" />"; echo "</div>"; echo "</form>"; } //ENTER TEXT BOX INFO INTO DB function insert_info($info,$page){ $sql = "UPDATE tbl_pages SET info = '".$info."' WHERE page = '".$page."'"; mysql_query($sql) or die (mysql_error()); header ("Location pageedits.php"); } // LOG THE USER OUT function user_logout(){ unset($_SESSION['user']); session_destroy(); header("Location: index.php"); } ?> for some reason when i enter nothing and click submit the error message dosnt appear, am i calling the function wrong? Link to comment https://forums.phpfreaks.com/topic/166434-solved-php-calling-a-function-and-returning-an-error-failing/ Share on other sites More sharing options...
Amtran Posted July 18, 2009 Share Posted July 18, 2009 First off, why are you passing $error as an argument in the function? I can't see a place where you use it, as you define $error within the function. Unless I'm missing something, remove that. Second, what is the error you get? Link to comment https://forums.phpfreaks.com/topic/166434-solved-php-calling-a-function-and-returning-an-error-failing/#findComment-877658 Share on other sites More sharing options...
mike12255 Posted July 18, 2009 Author Share Posted July 18, 2009 im not getting an error, its just not showing $error on index.php and i want it too Link to comment https://forums.phpfreaks.com/topic/166434-solved-php-calling-a-function-and-returning-an-error-failing/#findComment-877659 Share on other sites More sharing options...
mattal999 Posted July 18, 2009 Share Posted July 18, 2009 Well, you're returning the errors that you get from the function. Using: return $error; Will simply return the string that $error contained. Do this instead: <?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> Link to comment https://forums.phpfreaks.com/topic/166434-solved-php-calling-a-function-and-returning-an-error-failing/#findComment-877663 Share on other sites More sharing options...
Amtran Posted July 18, 2009 Share Posted July 18, 2009 im not getting an error, its just not showing $error on index.php and i want it too Ahhhhh, yes, mattal999 is correct. Link to comment https://forums.phpfreaks.com/topic/166434-solved-php-calling-a-function-and-returning-an-error-failing/#findComment-877665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.