iNko Posted November 2, 2012 Share Posted November 2, 2012 Hi, i uploaded my database to a server and now im just trying to connect to it this is my config file: <?php $con = mysql_connect ("my server details", "my server details", "my server details"); if (!$con) { die('Message if connection was bad: ' . mysql_error()); } mysql_select_db("my database name"); ?> And this is my login form code: <?php require('connectdatabase.php'); //takes config file info if(isset($_POST['submit'])) { $login = mysql_escape_string($_POST['login']); $password = mysql_escape_string($_POST['password']); $sql = mysql_query("SELECT * FROM `Vartotojas` WHERE `login` = '$login' AND `password` = '$password'"); if(mysql_num_rows($sql) > 0){ include('index.php'); exit(); }else{ echo "Bad login/password"; } }else{ ?> <form action="loginform.php" method="POST"> Login: <input type="text" name="login" /> <br/> Password: <input type="text" name="password" /> <br/> <input type="submit" name="submit" value="Login" /> </form> <?php } ?> This code works but i dont even need to login to connect to my index.php (i mean i can just type /index.php and it will go to that page bypassing the loginform.php) How do i make it so i could connect to index.php only when i go through loginform.php? (Do i need to add some code in my index.php so that it would check if im logged in?) Also, im not sure what this part does in this code : "if(mysql_num_rows($sql) > 0)" Link to comment https://forums.phpfreaks.com/topic/270194-login-to-database-problem/ Share on other sites More sharing options...
Muddy_Funster Posted November 2, 2012 Share Posted November 2, 2012 (Do i need to add some code in my index.php so that it would check if im logged in?) Also, im not sure what this part does in this code : "if(mysql_num_rows($sql) > 0)" How else do you expect index.php to know if you are logged in or not if it doesn't check? That bit of code is saying that if there was 1 or more records returned by your query, then do something (in your case : include the code that is in index.php on this page). Look into using sessions Link to comment https://forums.phpfreaks.com/topic/270194-login-to-database-problem/#findComment-1389561 Share on other sites More sharing options...
iNko Posted November 2, 2012 Author Share Posted November 2, 2012 thanks ill look into it Link to comment https://forums.phpfreaks.com/topic/270194-login-to-database-problem/#findComment-1389566 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.