taraw87 Posted February 8, 2008 Share Posted February 8, 2008 Hi Guys! Was wondering if you could help me out. This is kinda a php, mysql and html help thread all in one! I'm doing a project, and I must connect my website to a mysql database. I have come up with this code, but it doesn't seem to be working at all, when I enter a password and username (I have populated the databases) it just seems to refresh the page. Maybe a pair of fresh eyes can help as i've been at this for 2 days now. <?php #login.php session_start(); if (isset($_POST['username']) && isset($_POST['password'])) { $username = $_POST['username']; $password = $_POST['pass_word']; require_once ("./connections/connect.php"); $pagetitle = "Log in"; #require_once("./templates/header.php"); $query = "SELECT * FROM userpass where user_name = '$username' and pass_word = old_password('$password')"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $_SESSION['valid_user'] = $row['user_name']; $_SESSION['access_level'] = $row['access_level']; } if (isset($_SESSION['valid_user'])) { if($_SESSION['access_level'] == 1) { echo "<p>Welcome ".$_SESSION['valid_user'].", You are logged on as administrator</p>"; echo "<p>Go to <a href='admin_menu.php>Admin Menu</a></p>"; exit; } else if ($_SESSION['access_level'] == 2) { echo "<p>Welcome ".$_SESSION['valid_user'].", You are logged on as doctor</p>"; echo "<p>Go to <a href='doc_menu.php'>Doctor Menu</a></p>"; exit; } else if ($_SESSION['access_level'] == 3) { echo "<p>Welcome ".$_SESSION['valid_user'].", You are logged on as patient</p>"; echo "<p>Go to <a href='patient_menu.php'>Patient Menu</a></p>"; exit; } } } require_once("./templates/header.php"); ?> <div id="bodycontent"> <form action="login.php" method = "post" class = "contact" id ="theform"> <!--change #2--> <fieldset> <legend>Login</legend> <p> <label for="username" class ="fixed_required">User Name *</label> <!--change #3--> <input type="text" id="username" /> </p> <p> <label for="password" class ="fixed_required">Password *</label> <!--change #3--> <input type="password" id="password" /> </p> <p class = "submitbuttonarea" id = "submit"> <input type="submit" value="Submit" /> </p> </fieldset> </form> <p>* Required field</p> </div> <?php # require_once('./templates/footer.php'); ?> Also, this is my connections file, which works, but only if I comment out the headers and footers...any ideas? <?php #include ('./templates/header.php'); $connection = mysql_connect( "157.190.116.250", "walshtt", "R00009006") or die (mysql_error()); if ($connection) echo "Connection successful"; else echo "Connection failed"; #include ('/templates/footer.php'); ?> Thanks in advance for any help, I'd be so grateful Quote Link to comment https://forums.phpfreaks.com/topic/90044-php-connecting-to-database/ Share on other sites More sharing options...
benjaminbeazy Posted February 8, 2008 Share Posted February 8, 2008 umm without looking into anything just yet, i would suggest taking down your mysql host/user/pass Quote Link to comment https://forums.phpfreaks.com/topic/90044-php-connecting-to-database/#findComment-461662 Share on other sites More sharing options...
beansandsausages Posted February 8, 2008 Share Posted February 8, 2008 you have deffined $password = $POST[pass_word] but every where else its password including in the form to submit your details so change it to password Quote Link to comment https://forums.phpfreaks.com/topic/90044-php-connecting-to-database/#findComment-461665 Share on other sites More sharing options...
taraw87 Posted February 8, 2008 Author Share Posted February 8, 2008 umm without looking into anything just yet, i would suggest taking down your mysql host/user/pass Do you have to have a certain amount of posts before you can modify or delete a post, because I do not have any edit or delete buttons on my page. Can I request a mod to do it?? Thanks burnside...did that, still no joy. Will keep at it! Quote Link to comment https://forums.phpfreaks.com/topic/90044-php-connecting-to-database/#findComment-461668 Share on other sites More sharing options...
beansandsausages Posted February 8, 2008 Share Posted February 8, 2008 umm without looking into anything just yet, i would suggest taking down your mysql host/user/pass Do you have to have a certain amount of posts before you can modify or delete a post, because I do not have any edit or delete buttons on my page. Can I request a mod to do it?? Thanks burnside...did that, still no joy. Will keep at it! Okay try this : $password = $_POST['password']; <div id="bodycontent"> <form action="login.php" method = "post" class = "contact" id ="theform"> <!--change #2--> <fieldset> <legend>Login</legend> <p> <label for="username" class ="fixed_required">User Name *</label> <!--change #3--> <input type="text" id="username" name="username" /> </p> <p> <label for="password" class ="fixed_required">Password *</label> <!--change #3--> <input type="password" id="password" name="password" /> </p> <p class = "submitbuttonarea" id = "submit"> <input type="submit" value="Submit" /> </p> </fieldset> </form> <p>* Required field</p> Quote Link to comment https://forums.phpfreaks.com/topic/90044-php-connecting-to-database/#findComment-461669 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.