thewooleymammoth Posted August 31, 2007 Share Posted August 31, 2007 thanks for the help with the last problem btw now i have a new problem. I tried not to look at the sample code too much cause i wanted to figure out my own way of doing it. afterall it is practice. here is my code... <?php $username="root"; $password="php"; $database="userlist"; $table="login"; $connectmysql="mysql_connect(localhost,$username,$password)"; $selectdb="mysql_select_db('$database') or die('Could not select database')"; $query1="SELECT*FROM $table"; $query2="SELECT*FROM $table WHERE username='$user'"; $query3="SELECT*FROM $table WHERE username='$userpass'"; $result1="mysql_query($query1)"; $result2="mysql_query($query2)"; $result3="mysql_query($query3)"; $user2=$_COOKIE['auth']; if($_COOKIE['auth']) { echo "Welcome $user2 Enjoy the site"; } elseif (!isset($_POST['loggedin'])) { echo "<a>please login:</a><br> <form method='post' action='index.php'> Username:<input type='text' name='username'><br> Password:<input type='text' name='password'><br> <input type='submit' name='loggedin' value='Log In'><br> <a href='resister.php'>Register here</a>"; } elseif (isset($_POST['loggedin'])) { $user=$_POST['username']; $userpass = $_POST['password']; $connectmysql; $selectdb; if($user==$result2) { if($userpass == $result3) { echo "Thank you for logging in"; setcookie ("auth","$user"); } elseif ($user!=$result2) { echo "Sorry Wrong username/Password combonation"; } } } else { echo "error"; } ?> i get to the login form alright but when i press login the page goes blank and there is no source... idk why it would do that or what i should do to continue debugging... sorry to bother you guys so much. been trying to figure it out for a half an hour and i got no solution so far at all idk where to even start looking Quote Link to comment https://forums.phpfreaks.com/topic/67458-solved-my-login-script-again-newe-problem/ Share on other sites More sharing options...
Fadion Posted August 31, 2007 Share Posted August 31, 2007 $connectmysql="mysql_connect(localhost,$username,$password)"; The hostname should be a string. Change that line to: $connectmysql="mysql_connect('localhost',$username,$password)"; Quote Link to comment https://forums.phpfreaks.com/topic/67458-solved-my-login-script-again-newe-problem/#findComment-338653 Share on other sites More sharing options...
Fadion Posted August 31, 2007 Share Posted August 31, 2007 Oh and i just realized: $selectdb="mysql_select_db('$database'); mysql_select_db is a function. Where have u seen functions inside double quotes? Remove all the single and double quotes u have in functions: $selectdb=mysql_select_db($database); $connectmysql=mysql_connect('localhost',$username,$password); $result1=mysql_query($query1); Quote Link to comment https://forums.phpfreaks.com/topic/67458-solved-my-login-script-again-newe-problem/#findComment-338655 Share on other sites More sharing options...
thewooleymammoth Posted August 31, 2007 Author Share Posted August 31, 2007 alright cool thanks. i havnt seen em lol. Im basically brand new to programming i just went througha few shitty tutorials and looked up some functions sorry for my lack of competince Quote Link to comment https://forums.phpfreaks.com/topic/67458-solved-my-login-script-again-newe-problem/#findComment-338677 Share on other sites More sharing options...
noon Posted August 31, 2007 Share Posted August 31, 2007 The only thing worse than a noob is an over-apologetic noob. Don't have to say sorry all the time, that's what learning is about. Quote Link to comment https://forums.phpfreaks.com/topic/67458-solved-my-login-script-again-newe-problem/#findComment-338682 Share on other sites More sharing options...
soycharliente Posted August 31, 2007 Share Posted August 31, 2007 And did you mean to compare the username to the userpass? $query3="SELECT*FROM $table WHERE username='$userpass'"; You might need to change that if you are trying to compare passwords. Quote Link to comment https://forums.phpfreaks.com/topic/67458-solved-my-login-script-again-newe-problem/#findComment-338687 Share on other sites More sharing options...
thewooleymammoth Posted August 31, 2007 Author Share Posted August 31, 2007 ... alright... anyways now i get this error Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\served\website temp\index.php on line 6 Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\served\website temp\index.php on line 7 Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\served\website temp\index.php on line 7 Could not select database idk if you can help with this error or not, it might just be my setup... idk help appreciated Quote Link to comment https://forums.phpfreaks.com/topic/67458-solved-my-login-script-again-newe-problem/#findComment-338690 Share on other sites More sharing options...
thewooleymammoth Posted August 31, 2007 Author Share Posted August 31, 2007 And did you mean to compare the username to the userpass? $query3="SELECT*FROM $table WHERE username='$userpass'"; You might need to change that if you are trying to compare passwords. yea i saw that and changed it already thanks though Quote Link to comment https://forums.phpfreaks.com/topic/67458-solved-my-login-script-again-newe-problem/#findComment-338691 Share on other sites More sharing options...
soycharliente Posted August 31, 2007 Share Posted August 31, 2007 ... alright... anyways now i get this error Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\served\website temp\index.php on line 6 Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\served\website temp\index.php on line 7 Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\served\website temp\index.php on line 7 Could not select database idk if you can help with this error or not, it might just be my setup... idk help appreciated If we could see the code you are using NOW, that would help. Quote Link to comment https://forums.phpfreaks.com/topic/67458-solved-my-login-script-again-newe-problem/#findComment-338713 Share on other sites More sharing options...
thewooleymammoth Posted August 31, 2007 Author Share Posted August 31, 2007 <?php $makecookie=setcookie ('auth',$user); $username="root"; $password=""; $database="userlist"; $table="login"; $user=$_POST['username']; $userpass=$_POST['password']; $connectmysql=mysql_connect('localhost',$username,$password) or die(mysql_error()); $selectdb=mysql_select_db($database) or die(mysql_error()); $query=mysql_query("SELECT*FROM $table WHERE username='$user'"); $result=mysql_fetch_assoc($query) or die('error'); $user2=$_COOKIE['auth']; if($_COOKIE['auth']) { echo "welcome $user2"; } elseif (!isset($_POST['loggedin'])) { echo "<a>please login:</a><br> <form method='post' action='index.php'> Username:<input type='text' name='username'><br> Password:<input type='text' name='password'><br> <input type='submit' name='loggedin' value='Log In'><br> <a href='resister.php'>Register here</a>"; } elseif (isset($_POST['loggedin'])) { $connectmysql; $selectdb; if($user == $result['username']) { if($userpass == $result['password']) { $makecookie echo "You have logged in succesfully"; } elseif ($userpass != $result['password']) { echo "bad user/password combonation please try again.1"; } } elseif ($user !== $result['username']) { echo "bad user/password combonation please try again.2"; } } else { echo "error"; } ?> a freind helped me with those errors. and now i only get "error" but i think i can probably figure out whats going on with that. thanks again for the help Quote Link to comment https://forums.phpfreaks.com/topic/67458-solved-my-login-script-again-newe-problem/#findComment-338719 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.