Jump to content

login php code error... ideas?...


rootKID
 Share

Recommended Posts

yoyo dudes, i have a little trouble with my login page... here is my godes with my errors:

/*TEST #2*/if(isset($_POST['login_submit'])){$uname = $_POST['username']; //Form Name...$pass = $_POST['password']; //Form Name...if(isset($uname_checker)){$uname_stripped = strip_tags($uname);$pass_stripped = strip_tags($pass);header('location:succes_loader.php?login_checker=1');}else{$error_login_text = "Unknown username or password!...";}$query="SELECT * FROM user_login WHERE username ='$uname_stripped' && password='$pass_stripped'";$result=mysql_query($query);//kører forespørgsel$row = mysql_fetch_array($result);$_SESSION['uid'] = $row['user_id'];$_SESSION['user_name'] = $row['username'];$_SESSION['user_password'] = $row['password'];$_SESSION['u_email'] = $row['user_email'];echo "<fieldset><legend>Login Error!</legend>$error_login_text</fieldset><br>";}//End login_submit./*TEST #2*/

-------------------------------------------------------Error messeage here: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\speedscene\login.php on line 53 and yes, i am connected to db... :)... ideas would be greate! :)... PS: if i wish to make sha1 protection for my users... how to write on signup page and on login page?... thanks alot! :)...

Edited by rootKID
Link to comment
Share on other sites

Add mysql_error () to your query for more info. I think you're looking at a php error. You probably need the mysql_error(). EDIT: Also, are we looking at C:\xampp\htdocs\speedscene\login.php on line 53?

Edited by niche
Link to comment
Share on other sites

Guest So Called

Obviously $result is not a valid resource. One possible reason for that could be that your connect to database failed. How do you know that it succeeded? Follow the advice given by Niche above.

Link to comment
Share on other sites

I would think from now on you would have taken to heart the advice we give you in everyone of your posts. You need to debug and trace your steps through your code. We tell you this everytime. Have you looked up the functions you are using on the w3schools site, or in the php manual, in particular the ones related to the error? Where are you logging/outputting your variables? I don't see any error handling, or testing to confirm that all steps of your code are actually succeeding. No offense, but this should be your first line of defense EVERY TIME. Literally every post is the same; something doesn't work, or you have an error, but there is no indication of anything you have done to narrow it down to a specific line, variable, conditional, etc. Just sayin.

Link to comment
Share on other sites

I swear this has to be the most-asked question. The error message tells you exactly what the problem is, why can't people understand the error messages?

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\speedscene\login.php on line 53
So, what does that mean? It means that on this line: $row = mysql_fetch_array($result); $result is a boolean, not a MySQL result resource. So, what does that mean? Look at the documentation: http://www.php.net/m...mysql-query.php
Return Values For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.
Since your query is a SELECT query, and the function returns a boolean (which can only be false for select), then what does that mean? Like the description says, it means the query had an error. Look at the examples on that page to figure out how to get the error message from MySQL. And, in the future, pay attention when PHP is trying to tell you what the problem is. Error messages aren't just there for decoration, they're trying to tell you what PHP thinks the problem is.
Link to comment
Share on other sites

I swear this has to be the most-asked question. The error message tells you exactly what the problem is, why can't people understand the error messages?
I was just thinking the exact same thing. Maybe we just need to make a sticky for it....
Link to comment
Share on other sites

Guest So Called
Obviously $result is not a valid resource.
$result is a boolean, not a MySQL result resource.
It happens time after time.
and yes, i am connected to db... :)...
It's almost a sure thing that $result == FALSE. People tend to not read sticky posts just like they keep leaving out error checking code.
Link to comment
Share on other sites

sorry for late reply, and yeah... sorry... will try to hear a little more... the problem is that i have it into my soul to forget about stuff sometimes :)... and by the way, why i do know i have connection to db, is because of that i have a signup page connected also :P... and now i have tried with mysql error... and stupid me as allways... it was the SQL... no table name with the name user_login... the name should be users...and i think its working now... but one question more... when i hit enter and try to login... then its sending me to a page called succes_loader.php...and it does it even when im failing... where to put it in so it only does it when succes?... CODE:

/*TEST #2*/if(isset($_POST['login_submit'])){$uname = $_POST['username']; //Form Name...$pass = $_POST['password']; //Form Name...if(isset($uname_checker)){$uname_stripped = strip_tags($uname);$pass_stripped = strip_tags($pass);}else{$error_login_text = "Unknown username or password!...";}$query="SELECT * FROM users WHERE username ='$uname_stripped' && password='$pass_stripped'";$result=mysql_query($query)or die(mysql_error());//running query...$row = mysql_fetch_array($result); $_SESSION['uid'] = $row['user_id'];$_SESSION['user_name'] = $row['username'];$_SESSION['user_password'] = $row['password'];$_SESSION['u_email'] = $row['user_email'];echo "<fieldset><legend>Login Error!</legend>$error_login_text</fieldset><br>";header('location:succes_loader.php?login_checker=1');}//End login_submit./*TEST #2*/

thanks in advance! :)...

Link to comment
Share on other sites

You need to redirect when user is login means when database founds a match. you are not checking it so the redirection will happen anyway. you should use mysql_num_rows() to determine that query matches 1 rows and redirect when it fullfils it condition

Link to comment
Share on other sites

People tend to not read sticky posts just like they keep leaving out error checking code.
That's ok, in the future we can avoid another discussion of the problem just by linking them to the thread that describes how to solve it: http://w3schools.invisionzone.com/index.php?showtopic=44106
the problem is that i have it into my soul to forget about stuff sometimes
A good programmer doesn't need to memorize everything, I look up information every day that I've used before. The point is to pay attention to error messages and what they are trying to tell you. If you don't understand, look up the functions you're using in the PHP manual. You don't need to be a walking PHP encyclopedia, that's what php.net is for.
when i hit enter and try to login... then its sending me to a page called succes_loader.php... and it does it even when im failing... where to put it in so it only does it when succes?...
You're not checking if the query returned a row, you're just assuming it did. mysql_fetch_array will return false if there are no rows, you can use that to figure out if you should set the session data or if there was an error.
Link to comment
Share on other sites

if anyone just paste the error code in google, can get plenty of solution an explanations about those errors. people most of the time be lazy to look up on manual. but it is the most precious thing. i have not find any other documentation as well written and managed like php manual. they well seprated the parts of argument lists, probable exceptions, return values. those are the key points of function behaviour which is easy to lookup if anyone just take a look on the manual. and more over that user contribution of those manual pages has lot of usefull information and stuff to think about. it will be best to keep a copy of .chm copy of the manual with user contribution and trust me it will help more than anyone can imagine. No any tutorials or book can be substitute of the manual.

Edited by birbal
Link to comment
Share on other sites

That's ok, in the future we can avoid another discussion of the problem just by linking them to the thread that describes how to solve it:
I wasI was thinking about that some weeks ago. what i was thinking, to archive the most common errors,their quick solution and in depth description. That time it seemed like it will doing the job which has been done already, so i did not act. as you already started that topic, how about making it for possible common errors rather than specifically that error?
Link to comment
Share on other sites

Guest So Called

I have typed "php some_function_name" into Google's search box probably tens of thousands of times. When I'm writing code I often do that 2-3 dozen times a day. Then I read the function manual at PHP.net to refresh my understanding about how the function works. I often find I've forgotten some little detail that is sometimes the cause of my bug.

Link to comment
Share on other sites

hmm. ok... thanks... will try to see if i can find my error at php.net and post back if i could find somfthing, :).

Link to comment
Share on other sites

as you already started that topic, how about making it for possible common errors rather than specifically that error?
Feel free to add additional replies, we can always change the topic name.
I have typed "php some_function_name" into Google's search box probably tens of thousands of times.
I have a search hotkey mapped in Opera to search php.net, I can type in "p in array" and it will search php.net and find the reference for in_array. Pretty handy.
Link to comment
Share on other sites

Guest So Called

I always have FF open when I'm writing code. I just click the mouse in the search box and type "php some_function_name." PHP.net is always in the top 3-4 search results. Actually this would be a good application for a bookmarklet too. For those who haven't heard of bookmarklets, they're JavaScript stored in a browser bookmark. You hit the bookmark and it pops up a query box, enter the terms and click the button and it applies a search to the site it's programmed for.

Link to comment
Share on other sites

  • 2 weeks later...

hello guys, sorry for late reply as useally... i was busy doing job on outside my country... but im home for wednesday and then i have 3 weeks vecation time off :)... anyways, i have handled the proble,... but thanks for looking... and like i said earlier... will try to hear a little more... :).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...