Alexa
Members-
Posts
11 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
Alexa's Achievements
Member (2/5)
0
Reputation
-
Error session variable not displaying message in another php file
Alexa replied to Alexa's topic in PHP Coding Help
So, I tried your suggestion. The problem was that the form got submitted before entering the data. Anyway, https://codeshack.io/secure-login-system-php-mysql/ I found this site and from here I made a working login. I need to read more about php sessions and post and get. But one last question, for example if I start a session on the config/database.php file must I start another one in the login.php? Or the session must be uniquely defined in one folder? Thank you for all the help. I will mark both answers as solution as they helped me kind of figure out the problem. -
Error session variable not displaying message in another php file
Alexa replied to Alexa's topic in PHP Coding Help
I tried and implemented your suggestion, but the problem remains the same.. -
Error session variable not displaying message in another php file
Alexa replied to Alexa's topic in PHP Coding Help
So, I had some undefined variable errors and I solved them by deleting that code from the login_view.php file, as I don't need them now. But if I leave the input fields empty and hit submit, the problem remains the same: nothing happens, no error messages displayed -
Error session variable not displaying message in another php file
Alexa replied to Alexa's topic in PHP Coding Help
cyberRobot, thanks for the advice. I noticed there is a problem with the if(isset($_POST["submit"])), but I don't know how to solve it -
Error session variable not displaying message in another php file
Alexa replied to Alexa's topic in PHP Coding Help
I also tried to add session variables and the result is the same -
Error session variable not displaying message in another php file
Alexa replied to Alexa's topic in PHP Coding Help
<?php if($error["alert"] != ''){ echo "<div class='alert'>".$error["alert"]."</div>"; } ?> I also tried to add session variables and the result is the same -
Hi! I have 2 files based on the Model View Arhitecture. The file login.php and the config file containing the db connection are in the model folder and the login_view is in view folder. I am trying to make a login form am display some error messages to the user, but I don't get the error messages. Can you help me figure it out? PS: the connection to the db works fine! Thx! LOGIN.PHP <?php //start the session session_start(); foreach (glob("model/*.php") as $filename) { include $filename; } //form defaults $error["alert"]= ""; $error["user"]= ""; $error["pass"]= ""; $input["user"]= ""; $input["pass"]= ""; if(isset($_POST["submit"])) { //process form if($_POST["username"] == "" || $_POST["password"] == ""){ //display errors if($_POST["username"] == ""){$error["user"] = "required";} if($_POST["password"] == ""){$error["pass"] = "required";} $error["alert"] = "Please fill in the required fields"; //get the values for the username and password $input["user"]= $_POST["username"]; $input["pass"]= $_POST["password"]; include("../views/login_view.php"); } }else{ include("../views/login_view.php"); } LOGIN_VIEW.PHP <?php session_start(); foreach (glob("model/*.php") as $filename) { include $filename; } ?> <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <!--author:starttemplate--> <!--reference site : starttemplate.com--> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="keywords" content="unique login form,leamug login form,boostrap login form,responsive login form,free css html login form,download login form"> <meta name="author" content="leamug"> <title>Unique Login Form | Bootstrap Templates</title> <link href="/styles/style.css" rel="stylesheet" id="style" type="text/css"> <!-- Bootstrap core Library --> <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!-- Google font --> <link href="https://fonts.googleapis.com/css?family=Dancing+Script" rel="stylesheet"> <!-- Font Awesome--> <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> </head> <body> <!-- Page Content --> <div class="container"> <div class="row"> <div class="col-md-offset-5 col-md-4 text-center"> <h1 class='text-white'>Login Form</h1> <form action ="" method="POST"> <div class="form-login"></br> </br> <?php if($error["alert"] != ''){ echo "<div class='alert'>".$error["alert"]."</div>"; } ?> <div> <input type="text" name ="username" id="userName" class="form-control input-sm chat-input" placeholder="Username" value= "<?php echo $input['user'] ?>" required/> <?php echo $error['user'] ?> </div> </br></br> <input type="text" name ="password" id="userPassword" class="form-control input-sm chat-input" placeholder="Password" value= "<?php echo $input['password'] ?>" required/> <div class="error"> <?php echo $error['pass'] ?> </br></br> <div class="wrapper"> <input type="submit" class="btn btn-primary" value="submit"> </div> </div> </div> </form> </div> </div> </body> </html>
-
And benanamen, then, how should I do it?😀
-
Ok. I will try it. Can I also attach the whole files for you to be easier to check ?:)
-
The error is not displayed. Actually, nothing is displayed. Only a refresh to the page is done. I used the same piece of code for the login page, and there it works wonders.
-
Hi! I am trying to use the View Model Design Pattern in my application The problem is that it is the first time I use it and I am a beginner. So, I have the logic in the Model and the "front end" in View. I am talking about a sign up page. In the current Html file I am trying to access an error array from the model file and display it to the user above the input field. Here is the a snippet from the Model (Signup.php) $account = new Account($con); //the account which takes as param the db connection $error = null; //the array // anything the user writes gets inside this array if (isset($_POST["submitButton"])) { $firstName = UnifyFormInput::unifyUserFLName($_POST["firstName"]); $lastName = UnifyFormInput::unifyUserFLName($_POST["lastName"]); $username = UnifyFormInput::unifyFormUserName($_POST["username"]); $email = UnifyFormInput::unifyFormEmail($_POST["email"]); $password = UnifyFormInput::unifyFormPassword($_POST["password"]); //contain true or false based on the query being successful or not $success = $account->register($firstName, $lastName, $username, $email, $password); if ($success) { $_SESSION["userLoggedIn"] = $username; header("Location:index.php"); }else{ $error = $account->getError(Constants::$registerFailed); } } //compact — creates array containing variables and their values //call render function from View file to show the register page content View::render('register', compact('error')); And here is the view: <?php if (!empty($error)) { echo $account->getError(Constants::$loginFailed); } ?> <input type="text" class="form-control" name="firstName" placeholder= "First Name" value="<?php getInputValue("firstName"); ?>" required>