Jump to content

Recommended Posts

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 :)

Link to comment
https://forums.phpfreaks.com/topic/90044-php-connecting-to-database/
Share on other sites

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!

 

 

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>

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.