Jump to content

[SOLVED] my login script again, newe problem...


thewooleymammoth

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

... 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

 

Link to comment
Share on other sites

... 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.

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

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.