Jump to content

[SOLVED] LOGIN


brmcdani

Recommended Posts

Iam stuck on my login screen.  I have no clue what the deal is.  I don't know if I am not connecting to the database properly or what.  Here is what I have code wise and the screen shot is what I get when I run it in my browser.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$con = mysql_connect("localhost", "tutorial", "LsGQmFYsMBjUwvL4");
mysql_select_db("tutorial", $con);
$q = "SELECT * FROM `logintable` WHERE user='$usernamefield' AND pass='$passwordfield'";
$logincheck = mysql_query($q, $con) or die(mysql_error($con));

if(!isset($_POST['username']) || !isset($_POST['password'])){
   print "No username/password defined";}
print_r($logincheck)."<br/>";
print_r($rows);

$usernamefield = $_POST['username'];
$passwordfield = $_POST['password'];

$rows = mysql_fetch_array($logincheck);

if ($rows != "") {
echo "Welcome please select your lake";
}
else {

?>


<form id="form1" name="form1" method="post" action="">
  <p>
    <label>
      User Name:  
      <input type="text" name="username" id="username" />
    </label>
  </p>
  <p>Password: 
    <label>
      <input type="text" name="password" id="password" />
    </label>
  </p>
  <p>
    <label>
      <input type="submit" name="submit" id="submit" value="Submit" />
    </label>
  </p>
</form>
</body>
</html>

 

screen1-1.jpg

Link to comment
Share on other sites

Hi,

If you have php installed (which you do) but are getting a white screen, this means that you have a php error but the server has it's warnings turned off.

 

Glancing through your code I can see the following errors:

 

line 15.

You are missing various brackets.

You have this:

if(!isset($_POST['username']) || !isset($_POST['password'])){

it should probably be this:

if( (!isset($_POST['username']) || (!isset($_POST['password'])) ){

 

Then, you open an "if" but don't close it:

if ($rows != "") {
   echo "Welcome please select your lake";
}
else {

?>


<form id="form1" name="form1" method="post" action="">
  <p>
    <label>
      User Name: 
      <input type="text" name="username" id="username" />
    </label>
  </p>
  <p>Password:
    <label>
      <input type="text" name="password" id="password" />
    </label>
  </p>
  <p>
    <label>
      <input type="submit" name="submit" id="submit" value="Submit" />
    </label>
  </p>
</form>

After that closing form tag you need to open php again and close the "if":

 

</form>
<?php
}
?>

 

That should help you on your way.

 

Chris

 

Link to comment
Share on other sites

You have this:

if(!isset($_POST['username']) || !isset($_POST['password'])){

it should probably be this:

if( (!isset($_POST['username']) || (!isset($_POST['password'])) ){

 

Actually you don't need to add in extra brackets like that. His was fine, yours has a syntax error.

 

Also to add though, you're trying to use a variable before you've declared it. The $usernamefield and $passwordfield variables need to be moved before the query. You should also looking securing those inputs from XSS attacks. 1 more thing as well, to determine if the query successfully returned a matching row, use mysql_num_rows.

Link to comment
Share on other sites

Actually you don't need to add in extra brackets like that. His was fine, yours has a syntax error.

Opps, I missed a closing bracket in the middle there, not very helpful  of me :-[ sorry.

Of course you are right about not needing the extra brackets, I should have mentioned them as they aren't part of the problem.

 

Other than what you suggest about the correct way to check if the query has returned a result, I still think that the main problem here is the lack of the closing brackets on the "if" clause.

 

Sorry if I have caused any confusion, trying to do too many things at once, I need to step away from the keyboard for a while  :P

 

Chris

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.