Pudgemeister Posted August 4, 2006 Author Share Posted August 4, 2006 OMG OF COURSE!i can't believe i missed that :|cheers il have a test now... Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69168 Share on other sites More sharing options...
Pudgemeister Posted August 4, 2006 Author Share Posted August 4, 2006 still same error unfortunately.nethin else i can do? Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69174 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 [code]f ($num_1===0) { echo 'Your Password And/Or Username Are Not Correct-Please Try Again <a href="index.php">Here</a>'; } else { $query_2="SELECT id FROM users WHERE username='$username'"; $result_2=mysql_query($query_2) or die(mysql_error()); $id=mysql_num_rows($result_2); // returns numbers of matches found. echo "$id"; session_start(); $_session['$id']='$username';}; ?>[/code]why do I see a session start popped in the middle of all that code?? Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69177 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 also you don't call a session variable like that it's$_SESSION['whatever'] = "whatever";you have your session in all lowercase. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69178 Share on other sites More sharing options...
Pudgemeister Posted August 4, 2006 Author Share Posted August 4, 2006 ah-gd point. (hehehehehe)il have a go fixing that but as ive only just lernt sessions im not sure exactly where to put the session code.help? if u can?cheersPudgemeister Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69179 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 [code]echo 'Your Password And/Or Username Are Not Correct-Please Try Again <a href="index.php">Here</a>';[/code]also you should give your coding better form.[code]echo "Your Password And/Or Username Are Not Correct-Please Try Again <a href=\"index.php\">Here</a>";[/code] or something similar, you don't try and put strings together or do string manipulation with single quotes, when you get to more advanced code you will regret that habit. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69180 Share on other sites More sharing options...
Pudgemeister Posted August 4, 2006 Author Share Posted August 4, 2006 ok thanks for that-ne info on the sessions part?i understand sessions partly but i obviosly havent done it right-where would the first session start-and how would i i would like the session to actually be with the id and username. $_SESSION['$id] = $username if possible Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69181 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 session_start();at the top of EVERY page used with sessions.Inside the php.ini[quote]Session]session.save_handler[/quote]should be set to files unless your doing custom handlingsession name should be set to sessid and left at default unless you know what your doing, use only cookies is safer. if you change the max lifetime of the session cookie to a specific number of seconds, If you search on google they have a system to calculate second just put likenumber of seconds in 4 hours or something, it'll auto calculate that for you.My standard is 4 hours, it's fair to the person,a nd they can do what they need to do before it kicks them out, don't forget to hash your passwords.session.cookie_lifetime = 14400that will set you to 4 hours, you can double that for 8 hours, not recommended or safe, or you can lower it in quarters to recieve hourly. 25 percent of that is 1 hour, every other 25 percent of that is an extra hour.Or you can auto-calculate them in google as I said. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69182 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 exampleYou have a register formwhere they sign updon't forget on the password to put[code]$passhash = md5($password);[/code]or something similarThen when your ready to test, do this.[code]$password = md5($password);// this is going to check the password they typed during login against the hash of the password in the// database, so you know whether it's the same or not, and you still have encryption.$select = "SELECT username, password FROM userinfo WHERE username = '$username' AND password = '$password';":$query = mysql_query($select);if ($row = mysql_fetch_array($query)) {$_SESSION['username'] = $row['username'];$_SESSION['password'] = $row['password'];$_SESSION['controller'] = true;// I use controller to control what they can view/not view when logged in, I remove the login panel and// everything when there logged in, so I get full control with the controller session item.}else {echo "Go to hell you haven't logged in right";}}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69188 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 Now for cutting on and off people viewing things it's like[code]if ($_SESSION['controller'] === true) {// show what you want to show}else {echo "You have to be logged in to view this";}[/code]or you can reverse it to NOT display something WHEN someone is logged in Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69189 Share on other sites More sharing options...
Pudgemeister Posted August 4, 2006 Author Share Posted August 4, 2006 wo wo wo wo!!!!!!! people!!!!!!!i specifically said when posting in this topic u gota keep things as simple as u can. Like ur talking to a person who just discovered comps even.its what people do to confuse us noobs even more-shove a load of technical stuff in our mind and expect us to understand.KEEP IT FRIGGING SIMPLE! I CANT EXPRESS HOW AGGRIVATING IT IS WHEN PEOPLE DON'T EXPLAIN SIMPLY! IT'S NOT JUST ME EITHER.please can you explain that but simple for me please. because i dont even know any php command or what they do to do with sessions other than session start and session['summit'] = blaplease explain-simplePudgemeisterps-Keep It Simple Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69192 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 The bottom line is if you want it fed through a spoon go find another career. I learnt in 3 months, if I would have learnt SIMPLY I wouldn't have learn for 4 years, you either want to learn it or you don't. If you do shut up whining, take people's advice and get your ass out there and program. Books will help< I know this, but understand, too many books will waste your time you ahve to get your ass out there and build applications yourself to be a programmer. Simpler won't help. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69195 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 and if you want sessions, sessions are simple.On a basic level there are only 3 parts to sessions.RULE NUMBER 1-ALWAYS have session_start();at the very top of the page, BEFORE ANYTHING ELSEand don't keep any output, like echo's or print's too close to it, or it will still give you headers already sent. That is pretty straightforward, and always have session_start(); on every page you are wanting the sessions to carry over too.RULE NUMBER 2-if you want to create a session it's simple$_SESSION['username'] = $password;That's it, the same way you create a variable, and if you can't create a variable then how the hell can you learn sessions. Always it's the same thing.RULE NUMBER 3-when you begin getting ready to read those sessions(same as reading an array$_SESSION['username']that's itor $_SESSION[username]if it's in extrapolation (THIS MEANS- putting a variable inside of the middle of text for instanceecho "Hello this {$variable} got extrapolated in this echo statement.The same thing for sessionsecho "Hello this {$_SESSION[variable]} got extrapolated in this echo statement.";if you don't understand the basics of what I am talking about now, stop doing sessions, and go back and pick up php for dummies, until you have next to mastered1. variables and general variable theories2. arrays3. control structures examples if, elseif, while, do while, foreach, and whatever else.4. basic to intermediate string manipulationonce you know those THEN you can probably safety attempt sessions. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69199 Share on other sites More sharing options...
Pudgemeister Posted August 4, 2006 Author Share Posted August 4, 2006 ummm-thanx for simple (yet sort of rude) explanation o_0people have listened to me in past posts in this topic and posted things simply without being rude.but all the same-thanx to everyone. il go try it now. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69205 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 [code]if ($X != 1) {// do this}orif ($X != 1) {// do this} else {// do this if it is equal to 1!} // end if/else statement[/code]were do you get simple from, some of the stuff people posted on this, I don't even understand yet, some of this was far from simple. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69210 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 and I apologize for being rude, stuck on a dumb ass under-priced huge project, and I am a little pissed. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69212 Share on other sites More sharing options...
Pudgemeister Posted August 4, 2006 Author Share Posted August 4, 2006 nah im sory as wel-i startin college in a month and am lookin foreward to it so much i sorta tryin to get head start.i am learning php for a reason though-i have planned-my own big project that wil take a while-ts why im learning php in the first place.do u understand that code in ur comment?i remember it from when i couldnt even do if else codes hehe-think thats why he posted-to explain.if u dont i wil explain but i am guessing u do hehehe.ok i got my own prob now but i think i can sort it (i think)even when i put in the right username and password, now it still says somethin sis wrong :Soh well itl b ok.cheersPudgemeisterps sorry again Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69214 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 yes at this point, I understand almost everything I see with php/mysql, because of the hardships I faced in recent projects, I feel as thought I can do almost anything with php. My current difficulty is pagination but I am not doing that right now, I will create a new system myself later on down the road when I have time. The reason I learnt so fast, is I started creating everything I did from scratch. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69222 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 what is the error, line, or error message. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69224 Share on other sites More sharing options...
Pudgemeister Posted August 4, 2006 Author Share Posted August 4, 2006 its not an error-its the fact i been trying to get something but doing the wrong thing to get it.like i said erlier-in the table "users" in the database there is a field called "id" which is auto_increment.well i expected the [code]$query_2="SELECT id FROM users WHERE username = '$username' && password = '$password'"; $result_2=mysql_query($query_2) or die(mysql_error()); $id=mysql_num_rows($result_2);[/code]to get the id for that user that has successfully logged in correctly.of course that is totally wrong as all the $id variable is going to be is the number of rows that have the username and password to be what the user typed in (which since its a log in script, will always be 1 as no 2 usernames can be the same.i am trying to grab the id from the database that corresponds to the username and password and have it assigned to the variable "$id".corresponds? big word for me hehehe :Slol Pudgemeister Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69233 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 when you are allowing them to sign up simple have[code]<?php$select = "SELECT username FROM userinfo WHERE username = '$username';";$query = mysql_query($select);if (mysql_fetch_array($query)) {echo "I apologize but the username is already taken";}?>[/code]that's it,as for pulling the info where user name and password is testedafter they click submit to login it's[code]<?php$select = "SELECT username, password FROM userinfo WHERE username = '$username' AND password = '$password';";$query = mysql_query($select);if ($row = mysql_fetch_array($query)) {echo "You have logged in successfully";}?>[/code]these examples won't work but it'll give you an idea on wher eto start. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69237 Share on other sites More sharing options...
Pudgemeister Posted August 4, 2006 Author Share Posted August 4, 2006 oki could understand all of that but me being me i still made a bolocks up of my code.[code]if ($num===0) { echo 'Your Password And/Or Username Are Not Correct-Please Try Again <a href="index.php">Here</a>'; } else { $query_2="SELECT id FROM users WHERE username = '$username' && password = '$password'"; $result_2=mysql_query($query_2) or die(mysql_error()); $id=mysql_fetch_array($result_2); // returns the data found-hopefully. print $id;[/code]all i need now is:to assign the id number found in the table in the database to the variable $id and then print it.but no...me being me-i cant do it.Pudgemeister Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69248 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 [code]<?phpif ($num===0) { echo 'Your Password And/Or Username Are Not Correct-Please Try Again <a href="index.php">Here</a>'; } else { $query_2="SELECT id FROM users WHERE username = '$username' && password = '$password'"; $result_2=mysql_query($query_2) or die(mysql_error()); $id=mysql_fetch_array($result_2); // returns the data found-hopefully. print $id;?>[/code]ok if you don't clean this up like I said you'll regret it later your echo.And your trying to access your id wrongly. Here is the thing you don't understand right nowmysql_fetch_array()is meant to capture an ARRAY into the variable, meaning you have to understand arrays to do this, that's whY i said earlier basic's first, you can't jump straight to mysql queries without knowing other stuff, like arrays and general variables.THis is what your code should look likeprint is fine, but I find echo better, if you use print 1 itme in your script use all print, if you use echo, then use all echo it's neater.here is your code again, with what it should look like if you want it to do what you want.and I cleaned it up a bit.[code]<?phpif ($num===0) { echo "Your Password And/Or Username Are Not Correct-Please Try Again <a href=\"index.php\">Here</a>";}else {$query_2 = "SELECT id FROM users WHERE username = '$username' AND password = '$password';";$result_2 = mysql_query($query_2)$id = mysql_fetch_array($result_2); // returns the data found-hopefully.echo $row['id'];?>[/code]as you can see a few thigns you were doing are bad habits. Now the $row calls the array if you had of use$shithead = mysql_fetch_array($result_2);then you access it$shithead['id'];same thingyou access the array, followed by the value$row['id'];if you had other stuff you just replace the variable with the field name in your database$row['variable']: Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69254 Share on other sites More sharing options...
nethnet Posted August 4, 2006 Share Posted August 4, 2006 You also have to realize that MySQL syntax is different than PHP syntax. PHP uses comparison operators (such as == and &&), MySQL doesn't. You had these PHP operators in your MySQL query which was causing your errors. I know you want to learn everything as simple as posible, and avoid all of the technical jargon and whatnot, but you're going to kick yourself later when you HAVE to go back and relearn everything as you should have learnt it the first way. Believe me, it's not that hard if you just take the time to work with it. Like in the previous post, you are going to have to understand both MySQL and arrays before doing yoru database queries. You can't just echo your array without accessing an individual element. If what I'm saying confuses you, do a quick google search for PHP arrays and read some articles. This is very basic stuff and what you are trying to accomplish cannot be done without understanding it.Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69262 Share on other sites More sharing options...
Ninjakreborn Posted August 4, 2006 Share Posted August 4, 2006 yes when I rewrote the code I took that out, you can use some comparison operators but on variables, like less than greater than sometimes using sql operators are more helpful than pulling them into php and doing it, but for statements you HAve to use[quote]ANDOR[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/2/#findComment-69265 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.