PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
if ( isset($_POST['submit']) ) { // Fixed the writing of the POST array var
if ( empty($userid) ) { // Removed the '] from the end of user id and added a closing )
header("Location: http://www.mysite.com/memberok.php"); // Always ue a full URL for header redirects
} else {
echo 'Login incorrect.';
}
}
?>
OK, look at your code, then look at my code. There is one key diffrence in the second if. Find it and fix it and you will be golden. I have done this for you twice already so I am leaving it up to you to find it this time.
awesome.. it was the userid part that was messed.... i hadent posted my fix on the other...
IT WORKS NOW THOUGH!
There is still a slight problem though... I have it set to say Hi, [first_name], welcome to the members section..... It just says Welcome, . and does not load my first name. Is the $session tag done wrong?
echo "Welcome, ". $_SESSION['first_name'] .". You are now in our exclusive 'Members Only' section.<br>";
<?php
/* start the session */
session_start();
require("header.php");
include 'login_success.php';
/* this prints at the top of the page. */
echo "Welcome, ". $_SESSION['first_name'] .". You are now in our exclusive 'Members Only' section.<br>";
/* always prints the logout page, just in case the user is done */
echo "<br><br><b><a href=logout.php>Logout</a><br>";
?>
I have been testing stuff, and I typed in a wrong password and it still went thru to same screen..
therefore the problem must be in my authentification script?... I probably have this all effed up but atleast I know the messed is in here??? the memberok.php doesnt even matter cuz I know its not reading right.
<?php
session_start();
require("header.php");
include ("login_success.php");
include("db.php");
$_SESSION['first_name'] = $first_name;
/* this prints at the top of the page. */
echo "Welcome, ". $first_name .". You are now in our exclusive 'Members Only' section.<br>";
/* always prints the logout page, just in case the user is done */
echo "<br><br><b><a href=logout.php>Logout</a><br>";
?>
</td></tr>
</table>
</center>
</body>
</html>
Where are you setting $first_name? It appears that you are either relying on register_globals setting it for you or you are assuming that the $_POST['first_name'] var will automatically read into the $first_name var? Unless you give the var $first_name a value, it will return an undefined variable notice and evaluate to false in your script.
I don't think that code is going to do it, dull1554. The code you posted checks for a form field called submit to see if it is set, the checks to see if the var $userid is empty and if it is, sends them to memberok.php (incorrectly, I should add... Use a full URL).
What I think is happening here is that you are using an old tutorial that is relying on register_globals being on. What you want to do is check to see if there is a form submitted, and if it is, use the fields in $_POST array to set your session vars (after checking them for validity).
I think Maugrim_the_Reaper created a Challenge/Response snippet in the code snippets forum in this community. Try looking that up and if it doesn't give you a point inthe right direction, post back. It is fairly simple to do, but there is some coding involved.
No... I am trying to read from a MySQL database not a form.
Also, what dull1554 posted, isnt what im looking for... I think I misportrayed it.
I am just looking to post variables in the database really. It will read their userid from their login info and I will be able to post whatever I want from their profile..
Ill look more in code snippets, but its probably something simple that I am missing and am just too inexperienced to be able to pick up.
4Boredom wrote:No... I am trying to read from a MySQL database not a form.
How does MySQL know what select?
4Boredom wrote:I am just looking to post variables in the database really. It will read their userid from their login info and I will be able to post whatever I want from their profile..
At some point, in order to do this, you will need to interact with a form. When the form is submitted you will need to capture the data sent by the form. Hence the need for the $_POST array. Once you read the $_POST array vars into regular vars, then you can do what you want with them. But you are going to be interacting with a form at some point because MySQL will not know what person's data you want unless the script tells it which person. That is usually done through a login script of some sort.
ok i get the post thing to show... but its not even registering the login.... I can type a wrong pw and it goes thru (to same screen with no name given like as if i can typed right pw).....
So yea... with that code I gave, why isnt it registering my login?? ANyone know?