you use the variable $YearofStudy, but you don't define it, may as well use the variable $rtjorvkijuwturchjrvecguwhrecmy, or any other random one you like.
Intranet log in system
sorry I am coming across as random but I don't understand where I am supposed to put the Variable $YearofStudy ?
"if ($YearofStudy=="Year 1") "
where do you think you defined the value for $YearofStudy ?
"if ($YearofStudy=="Year 1") "
where do you think you defined the value for $YearofStudy ?
I am very sorry but I don't understand if that is the defined your asking about is it wrong? do I need to replace it or move it?, I know I sound like I have not got a clue but its right I dont have a clue, that is why I joined to talk to people who do no what there talking about.
I really do appreciate your help
Dicko;10998832 wrote:Its in my database and in the Registration form, just double checked database and the entry has been entered for Year 1 student, but some reason does not direct that user to there.
because $YearofStudy is never "year 1" or anything else, as its never defined.
Dicko;10998832 wrote:"if ($YearofStudy=="Year 1") "
where do you think you defined the value for $YearofStudy ?
I am very sorry but I don't understand if that is the defined your asking about is it wrong? do I need to replace it or move it?, I know I sound like I have not got a clue but its right I dont have a clue, that is why I joined to talk to people who do no what there talking about.
I really do appreciate your help
wrong well it results in the error above; can you answer the question as to where you think it is defined?
If the data is supposed to be coming from the DB, then you've got two problems:
Your if() statement comes before this line:
$row = mysql_fetch_assoc($res);
which appears to be the only place you actually fetch information from the DB. In other words, PHP isn't psychic and can't predict what the value is before you actually retrieve it.
You never define the variable $YearofStudy based on the associative array $row. For example, $row['YearofStudy'] may contain the information you need, but if that's the case then you'd need to define $YearofStudy based on that information.
Should be added on this line so when it checks the db for username and password it also checks the year?
$res = mysql_query("SELECT * FROM users
WHERE username
= '".$username."' AND password
= '".$password."'");
I have done some alteration ;
//split all fields fom the correct row into an associative array
$row = mysql_fetch_assoc($res);
//direct them to the usersonline page
($row['YearofStudy'] !="Year 1");
if($YearofStudy=="Year 1");
{
header("location: 1st Year.php");
}else{
header("location: Year2Homepage.php");
}
and I am now getting the following error;
Parse error: syntax error, unexpected T_ELSE in /#####/#####/######/index.php on line 105
($row['YearofStudy'] !="Year 1");
err what does this mean? or even try and do ?
As dagon's questions allude to, this statement:
//direct them to the usersonline page
($row['YearofStudy'] !="Year 1");
seems incorrect (especially since it doesn't do anything).
Instead, you either need to define the variable $YearofStudy (probably setting it equal to the value in $row['YearofStudy']), or even better, get rid of references to $YearofStudy altogether and simply use $row['YearofStudy'].
Thanks Brad that makes more sense I will give it a go and let you know
Hi Brad,
I tried that and that through up another error and wouldn't display the page error message is;
Parse error: syntax error, unexpected T_ELSE in /######/######/######/index.php on line 105
This is the code and the "else" 105 refers to is after header("location: 1st Year.php");
$row = mysql_fetch_assoc($res);
//direct them to the usersonline page
$row['YearofStudy'];
if($YearofStudy=="Year 1");
{
header("location: 1st Year.php");
}else{
header("location: Year2Homepage.php");
}
//check to see if the user has not activated their account yet
if($row['active'] != 1){
//if not display error message
echo "<center>You have not yet <b>Activated</b> your account!</center>";
}else{
//if they have log them in
//set the login session storing there id - we use this to see if they are logged in or not
$_SESSION['uid'] = $row['id'];
//show message
echo "<center>You have successfully logged in!</center>";
//update the online field to 50 seconds into the future
$time = date('U')+50;
mysql_query("UPDATE `users` SET `online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'");
}
}
}
}
}
?>
Thanks again
if($YearofStudy=="Year 1");
You have a spurious semicolon on this line.
Thanks Weedpacket,
That has got the index page back to displaying, but it still will only take me to the 2nd year home page not the 1st year?
This statement:
//direct them to the usersonline page
$row['YearofStudy'];
still does absolutely nothing and might as well be omitted. Likewise, you're still using an undefined variable $YearofStudy here:
if($YearofStudy=="Year 1");
{
header("location: 1st Year.php");
}else{
header("location: Year2Homepage.php");
}
where you should have been using $row['YearofStudy'] (or else you should've defined the variable $YearofStudy first).
Hi Guys,
I am really sorry but I am not getting this at all, I have tried changing the text around and I can either get a page that does not open at all or one that opens and just sends me to the year 2 page.
I do not understand how to create and define a variable
//direct them to the usersonline page
$row['YearofStudy']
{
header("location: 1st Year.php");
}else{
header("location: Year2Homepage.php");
}
this is the latest failed attempt :o
Dicko;10998908 wrote:I do not understand how to create and define a variable
http://www.php.net/manual/en/language.variables.basics.php Variables are one of the most basic essences of any programming language. You should really understand how they work and how to use them before you try to do anything else with a language. As such, assigning the value of $row['YearofStudy'] to a variable called $YearofStudy is as simple as:
$YearofStudy = $row['YearofStudy'];
But again, you really REALLY need to learn and understand variables.
Thanks for that, I feel like I need to let you know a little of my background so just maybe you can understand why I dont understand.
I am 40 and up to 4 years ago I was a coach builder when I underwent 3 major operations and since then have had increasing health problems. I soon realized I would not be able to return to work in a physical role and had 2 options either I sit on bum and live off the state or I go about retraining myself.
I had never done anything IT related at this point in fact my 1st pc was in 2002 so all I had done was go on the net. So I had to start at the bottom doing the ECDL courses then a few night time courses until I got were I am today doing a Networking degree which does not involve programming. Like I said at the beginning I have tried to teach myself even bought books and online tutorials but I just cant get the hang of php. So as forum's are set up to help people I thought it would be a good idea to join, but I am feeling just as frustrated if not more so than I was before
Well my advice to you would be get familiar with basics first and foremost before you try creating fully functional application. The whole run before you walk thing. Start by making a page that's basically static, and without any DB interaction, or user interaction just yet. Thought I would recommend you be proficient in your HTML (if you're not, you may be, I don't know that) before you try to use PHP. The reasoning behind this is your using PHP to output HTML, and if you don't know how to write that HTML on your own, how are you going to tell PHP to write it? (hint you can't)
Basically I feel like you are trying to do way WAY too much at once. Start small and understand what you're doing and how it works before you move on to doing more. If you're having trouble with variables than understanding control structures and database abstraction it going to be next to impossible.
I suggest you start here http://www.php.net/manual/en/getting-started.php and work you're way thru the links on that page following all the examples. Then you can skip to Language reference and work your way down from here. If you have problems writing code using the instructions and examples provided then come back here and ask for more help. The very last thing I would ever tell you to do is hold a question because its in an early chapter. Better to understand a basic variable now then get lost on something later because you never understand the building blocks.
I hope you don't read this as condescending, in fact I mean far from it. I applaud you in taking the steps to learn a new skill later in life. I worked in kitchens for near 15 years myself before I started doing programming of any kind. And I can tell you right now you know WAY WAY more than me about networking, conversing I know more than you about programming. But a little time and patience (patience is very key!) and you will probably know more than me someday and you will definitely know more than someone else who's just starting soon.
Thanks Derokorian, I will take your words on board, it just so frustrating when I even managed to write an earlier model of this site and have a log in system that worked but only to one page to then scrap that and rebuild so many times using different tutorials for the sole purpose of having a bidirectional system, when I could have either gone down the easy route created 2 separate sites or a site that once logged in the user decided which direction to go. I just wanted it to be fully functional so it can be passed to another student to take as a project to expand upon the work I have done with it.