jay93 Posted February 27, 2013 Share Posted February 27, 2013 hi, i m currently working on resetting password feature on my website, and this is what i've got for my pass.php file which receives POST from pass_form.php... anytime i run localhost/pass.php, nothing happens, it always keeps on returning the localhost/login.php (which is my login page)... where could the problem be?? ----apologize and query are functions i'm using to display errors and to interact with teh SQL database respectively... <?php // configurationrequire("../includes/config.php"); if ($_SERVER["REQUEST_METHOD"] == "POST"){if (empty($_POST["forgotpassword"]))apologize("Please enter email address.");if (empty($_POST["security"]))apologize("Please enter your security key.");$email = $_POST["forgotpassword"]; if(!(filter_var($email, FILTER_VALIDATE_EMAIL)))apologize("Please enter a valid email such as example@domain.com");//check if email and securitykey exist in users table$check= query("SELECT id, security FROM users WHERE email = ?", $_POST["forgotpassword"]);if ($check === false){apologize("No such user in database");}else render("reset.php", ["title" => "Reset Password", "check" => $check]); and is this right?? i'm trying to pass the id from this file into another page called reset.php(user inserts new password here), where i access the id this$check[id]..??}else {render("login.php", ["title" => "Login"]);}?> Quote Link to comment https://forums.phpfreaks.com/topic/275010-nothing-displays/ Share on other sites More sharing options...
Barand Posted February 27, 2013 Share Posted February 27, 2013 I have no idea what your render() function does, but if you are trying to pass it an array, use render("reset.php", array("title" => "Reset Password", "check" => $check) ); Quote Link to comment https://forums.phpfreaks.com/topic/275010-nothing-displays/#findComment-1415364 Share on other sites More sharing options...
jay93 Posted February 27, 2013 Author Share Posted February 27, 2013 this is my render function...i just realized reset.php is actually a controller instead of a template, could that be causing it??? i actually wanted to pass in the id value that corresponds to email, to reset.php, so that i could use it in reset.php thus... $result = ("UPDATE users SET hash = ? WHERE id = ?", crypt($_POST["password"], $check["id"]); if($result===false) apologize("Could not register. Please retry."); function render($template, $values = []) { // if template exists, render it if (file_exists("../templates/$template")) { // extract variables into local scope extract($values); // render header require("../templates/header.php"); // render template require("../templates/$template"); // render footer require("../templates/footer.php"); } // else err else { trigger_error("Invalid template: $template", E_USER_ERROR); } and by the way, i'm having a similar error with my reset.php file too, whenever i type localhost/reset.php, it just ends up on the login.php page... Quote Link to comment https://forums.phpfreaks.com/topic/275010-nothing-displays/#findComment-1415371 Share on other sites More sharing options...
computermax2328 Posted February 27, 2013 Share Posted February 27, 2013 Well to start, both of your if(empty) statements and if(!filter_var) don't have brackets, therefore no argument. They say if this.... and then nothing happens. Doesn't matter if the statement is true or false, the argument does not exist. Also in your query it says WHERE=?. Get rid of the questions mark and the post statement and just put WHERE=$email. You already set the variable. Use the mysql_real_escape_string() all of your POSTs to help prevent mysql injection. Finally, around your query it is mysql_query() not query(). I will keep looking... Quote Link to comment https://forums.phpfreaks.com/topic/275010-nothing-displays/#findComment-1415385 Share on other sites More sharing options...
jay93 Posted February 27, 2013 Author Share Posted February 27, 2013 thanks for the reply... i did the bracket stuff, but it's still giving me the same problem...r whenever i try to open pass.php thus localhost/pass.php, it doesnt open, but instead the localhost/login.php shows, which is my login page... but when i login and then try to open pass.php, then i face another problem...it displays the login_form.php template linked to the login.php controller (in other words, the login page, even though the user is logged in)... regarding "query" it's a function i'm using to get data from the sql table... this is what i have now for pass.php: <?php // configuration require("../includes/config.php"); if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["forgotpassword"])) { apologize("Please enter email address."); } if (empty($_POST["security"])) { apologize("Please enter your security key."); } $email = $_POST["forgotpassword"]; if(!(filter_var($email, FILTER_VALIDATE_EMAIL))) { apologize("Please enter a valid email such as example@domain.com"); } //check if email and securitykey exist in users table $check= query("SELECT id, security FROM users WHERE email = $email"); if ($check === false) { apologize("No such user in database"); } render("reset.php", ["title" => "Reset Password", "check" => $check]); } else render("login_form.php", ["title" => "Login"]); ?> and my template for pass.php, pass_form.php is <form action="pass.php" method="post"> <fieldset> <div class="control-group"> <input name="forgotpassword" placeholder="Email" type="text"/> </div> <div class="control-group"> <input name="security" placeholder="Security Keyword" type="text"/> </div> <div class="control-group"> <button type="submit" class="btn">Reset</button> </div> </fieldset> </form> and just to give you a hint of what i'm trying to do, i'm planning to implement a recover function thus: 1. when the user clicks on "forgot password" on localhost/login.php without already being logged in, it should take them to a page, pass.php (displaying an email field and security question field)... 2.and when the users enter both( confirm if they exist in the sql table), then redirect to another form reset.php which shows two fields for "Enter new password" and "Confirm password", and when user enters both, his password is updated in the database... Pass.php has a template pass_form.php and reset.php has a template reset_form.phpp Quote Link to comment https://forums.phpfreaks.com/topic/275010-nothing-displays/#findComment-1415388 Share on other sites More sharing options...
Jessica Posted February 27, 2013 Share Posted February 27, 2013 Well to start, both of your if(empty) statements and if(!filter_var) don't have brackets, therefore no argument. They say if this.... and then nothing happens. Doesn't matter if the statement is true or false, the argument does not exist. Also in your query it says WHERE=?. Get rid of the questions mark and the post statement and just put WHERE=$email. You already set the variable. Use the mysql_real_escape_string() all of your POSTs to help prevent mysql injection. Finally, around your query it is mysql_query() not query(). I will keep looking... It looks like OP is using a wrapper for his queries that should handle making prepared statements. Going back to mysql_query and real_escape_string will be LESS secure, if he's using PDO or mysqli. Quote Link to comment https://forums.phpfreaks.com/topic/275010-nothing-displays/#findComment-1415389 Share on other sites More sharing options...
jay93 Posted February 27, 2013 Author Share Posted February 27, 2013 @jessica, yeah, i'm using that in my query() function...did you see my latest post, it's about at the same time as urs??? Quote Link to comment https://forums.phpfreaks.com/topic/275010-nothing-displays/#findComment-1415392 Share on other sites More sharing options...
computermax2328 Posted February 27, 2013 Share Posted February 27, 2013 My bad. Disregard me.... I will go somewhere else Quote Link to comment https://forums.phpfreaks.com/topic/275010-nothing-displays/#findComment-1415400 Share on other sites More sharing options...
jay93 Posted February 27, 2013 Author Share Posted February 27, 2013 found the solution to that problem, in my config.php file declared at the top, i was initializing SESSION...hence the problem...however, the new issue now is my render function works for only templates, so it is rejecting render.php as an invalid template...is there a way i can pass the values in the array $check to my reset.php (which is a controller , not template) , so i could access them in reset.php thus.. (boldened)...and is my logic right??<?php// configurationrequire("../includes/config.php");// if form was submittedif(isset($_POST["submit"])){if (empty($_POST["password"]))apologize("Please enter password.");if ($_POST["password"] != $_POST["confirmation"])apologize("Passwords do not match!");$result = query("UPDATE users SET hash = ? WHERE id = ?", crypt($_POST["password"], $check[0]["id"]));if($result===false)apologize("Could not register. Please retry.");else{$rows = query("SELECT id FROM users WHERE hash = ?", crypt($_POST["password"]));$id = $rows[0]["id"];// remember that user's now logged in by storing user's ID in session$_SESSION["id"]= $rows[0]["id"];}// redirect to portfolioredirect("register.php");}else{// else render formrender("register_form.php", ["title" => "Register"]);}?> Quote Link to comment https://forums.phpfreaks.com/topic/275010-nothing-displays/#findComment-1415417 Share on other sites More sharing options...
jcbones Posted February 27, 2013 Share Posted February 27, 2013 Wrap code in [ code ] [ /code ] blocks. It makes it easier to read. There is no way to correctly answer your question without posting your controller class and your template class. Quote Link to comment https://forums.phpfreaks.com/topic/275010-nothing-displays/#findComment-1415475 Share on other sites More sharing options...
jay93 Posted February 28, 2013 Author Share Posted February 28, 2013 this is what i've got for reset.php.....like i mentioned earlier, is there a way to pass into reset.php the value of $check so that i can use $check[0][id] in it as shown above boldfaced... <?php // configuration require("../includes/config.php"); // if form was submitted if(isset($_POST["submit"])) { if (empty($_POST["password"])) apologize("Please enter password."); if ($_POST["password"] != $_POST["confirmation"]) apologize("Passwords do not match!"); $result = query("UPDATE users SET hash = ? WHERE id = ?", crypt($_POST["password"], $check[0]["id"])); if($result===false) apologize("Could not register. Please retry."); else { $rows = query("SELECT id FROM users WHERE hash = ?", crypt($_POST["password"])); $id = $rows[0]["id"]; // remember that user's now logged in by storing user's ID in session $_SESSION["id"]= $rows[0]["id"]; } // redirect to portfolio redirect("register.php"); } else { // else render form render("register_form.php", ["title" => "Register"]); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/275010-nothing-displays/#findComment-1415550 Share on other sites More sharing options...
jcbones Posted February 28, 2013 Share Posted February 28, 2013 Yes, just include the reset.php into the file that uses $check. Quote Link to comment https://forums.phpfreaks.com/topic/275010-nothing-displays/#findComment-1415717 Share on other sites More sharing options...
Solution jay93 Posted March 2, 2013 Author Solution Share Posted March 2, 2013 thanks for your help... i had another question, related to C, linked lists though...could you please help?? assuming you had a double linked list of integers, and three pointer first___ which is a global pointer_, prev and next ...and you had to create a struct node like the following, how will you fill in the dashes?? typedef struct node{_______ prev; // Box I_______ i; // Box II_______ next; // Box III}node; if you look at the function below for a double linked list, does it properly insert items into the tail of the list?? and does it segfaults when inserting into an empty list ie.when first is NULL).?? and what about mem leakage> does it leak when inserting i into an existing list?? thanks void insert(unsigned int i) { node* n = malloc(sizeof(node)); if (n == NULL) { return; } n->prev = NULL; n->i = i; n->next = NULL; if (first == NULL) { first = n; } else if (n->i < first->i) { n->next = first; first->prev = n; first = n; } else { node* ptr = first; while (true) { if (ptr->i == n->i) { return; } else if (ptr->next->i > n->i) { n->next = ptr->next; ptr->next->prev = n; n->prev = ptr; ptr->next = n; return; } ptr = ptr->next; } } } Quote Link to comment https://forums.phpfreaks.com/topic/275010-nothing-displays/#findComment-1415990 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.