Metorium Posted October 25, 2014 Share Posted October 25, 2014 I am trying to create a log in page but all that comes up is Please enter a username and password <?php session_start () ; $username = $_POST ['username'] ; $password = $_POST ['passowrd'] ; if ($username&&$password) { define ('DB_HOST' , 'localhost') ; define ('DB_USER' , 'root') or die ("Could not connect!") ; define ('DB_PASSWORD', "") or die ("Could not find DB!") ; define ('DB_DATABASE', 'joke') ; } else die ("Please enter a username and password") ; $query = mysql_query ("SELECT * FROM Joke WHERE username = '$username'") ; $numrow = mysql_num_rows ($query) ; if ($numrows!=0) { //code to login While ($row= mysql_fetch_assoc($query)) { $dbusername = $row ['username'] ; $dbusername = $row ['password'] ; } //check if they match if ($username==$dbusername&&$password==$dbpassword) { echo "You're inn! <a href=member.php> Click here to enter member page" ; $_SESSION['username']=$dbusername ; } else echo "incorrect password!" ; } else die("That user does'nt exist") ; echo $numrows; ?> Quote Link to comment https://forums.phpfreaks.com/topic/292053-what-have-i-done-wrong-here/ Share on other sites More sharing options...
KillerOz Posted October 25, 2014 Share Posted October 25, 2014 In your elses, you didn't use {}, i think that's the problem Quote Link to comment https://forums.phpfreaks.com/topic/292053-what-have-i-done-wrong-here/#findComment-1494701 Share on other sites More sharing options...
Barand Posted October 25, 2014 Share Posted October 25, 2014 You have defined the host, user etc but you still need to connect to the database before you can execute any queries. And you should not be creating new code using the mysql_xxxx functions, use mysqli_xxxx or PDO functions. @KillerOz, the {} are advisable but not essential for a single statement Quote Link to comment https://forums.phpfreaks.com/topic/292053-what-have-i-done-wrong-here/#findComment-1494702 Share on other sites More sharing options...
Metorium Posted October 25, 2014 Author Share Posted October 25, 2014 Hey barand thank you for helping meI am a college student and i want to do website production when im older. I learnt HTML at school but want to try and teach myself some PHPYou said i need to define the host, how do i go about doing that?also i am useing 000webhost at the moment (not permanent) and i dont think they support mysqli Quote Link to comment https://forums.phpfreaks.com/topic/292053-what-have-i-done-wrong-here/#findComment-1494709 Share on other sites More sharing options...
Barand Posted October 25, 2014 Share Posted October 25, 2014 As a prerequisite to learning PHP you need to learn to read. You said i need to define the host, how do i go about doing that? I said you have defined the host etc but you have not connected to the server. http://uk3.php.net/manual/en/function.mysqli-connect.php Quote Link to comment https://forums.phpfreaks.com/topic/292053-what-have-i-done-wrong-here/#findComment-1494710 Share on other sites More sharing options...
Ch0cu3r Posted October 25, 2014 Share Posted October 25, 2014 You said i need to define the host, how do i go about doing that? Go back and read Barand's post again. also i am useing 000webhost at the moment (not permanent) and i dont think they support mysqli To find out of they do support mysqli run phpinfo. IMO it would be better to install the AMP stack locally on your computer. You can either install it manually or use packages such as XAMPP, WAMP or MAMP Quote Link to comment https://forums.phpfreaks.com/topic/292053-what-have-i-done-wrong-here/#findComment-1494711 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.