Jump to content

New Cookie Problem


carleihar

Recommended Posts

I've somewhat figured out my cookie login problem. I feel like I'm so close but now I'm stuck. I've been looking at this for hours.

<?php

// Make the connection:
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
//(this is actually filled out)

if(isset($_COOKIE['username']) || $_COOKIE['password']){  
$username = $_COOKIE['username'];  
$password = $_COOKIE['password'];  

if (isset($_COOKIE['username']) && ($_COOKIE['password'])){  
	echo 'cookie logged in<br />';  
	echo 'Click <a href="logout.php">here</a> to log out';  
}  

}  

if(isset($_POST['submit'])){  //if the form has been submitted


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

if ($result = mysqli_query($dbc, "SELECT COUNT(*) FROM users WHERE username='" . $username . "' AND password='" . $password . "'")) { 
    	$row = mysqli_fetch_assoc($result);  
	  
	 if ($row['COUNT(*)'] == 1) { 

	setcookie("username", $username, time()+3600, "/");  
	setcookie("password", $password, time()+3600, "/");  
	echo 'logged in<br />';  
	echo 'Click <a href="logout.php">here</a> to log out';

	?>

        <script language="javascript">

	window.location = "http://www.liveequian.com/htdocs/pages/login_main.php";

	</script>

	<?php

	} else {   //the username does not match

	echo 'Log in failed';  

	}  

} else {

	echo 'something failed. who knows.';

}

}  else {   //the form was not submitted 

if(!isset($_COOKIE['username'])){  
	echo '<form action="" method="POST">';  
	echo 'Username - <input name="username" type="text"><br />';  
	echo 'Password - <input name="password" type="password"><br />';  
	echo '<input name="submit" type="submit" value="Submit"><br />';  
	echo '</form>';  
}  else {
	echo 'You are already logged in!';
}
}  
?>

 

It comes out with: "something failed. who knows."

 

Alternatively, this code comes up with "Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/e/q/u/equianadmin/html/htdocs/pages/loginhelp.php on line 33

Log in failed"

<?php 

// Set the database access information as constants:
DEFINE ('DB_USER', 'liveequianusers');
DEFINE ('DB_PASSWORD', 'Salliell9.');
DEFINE ('DB_HOST', 'liveequianusers.db.5225436.hostedresource.com');
DEFINE ('DB_NAME', 'liveequianusers');

// Make the connection:
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);


if(isset($_COOKIE['username']) || $_COOKIE['password']){  
$username = $_COOKIE['username'];  
$password = $_COOKIE['password'];  

if (isset($_COOKIE['username']) && ($_COOKIE['password'])){  
	echo 'cookie logged in<br />';  
	echo 'Click <a href="logout.php">here</a> to log out';  
}  

}  

if(isset($_POST['submit'])){  //if the form has been submitted


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

	$q = "SELECT username FROM users WHERE (username='$username' AND password=SHA1('$password')";		
	$r = mysqli_query ($dbc, $q);

	if (mysqli_num_rows($r) == 1) { // A match was made.

	setcookie("username", $username, time()+3600, "/");  
	setcookie("password", $password, time()+3600, "/");  
	echo 'logged in<br />';  
	echo 'Click <a href="logout.php">here</a> to log out';

	?>

        <script language="javascript">

	window.location = "http://www.liveequian.com/htdocs/pages/login_main.php";

	</script>

	<?php

	} else {   //the username does not match

	echo 'Log in failed';  

	}  



}  else {   //the form was not submitted 

if(!isset($_COOKIE['username'])){  
	echo '<form action="" method="POST">';  
	echo 'Username - <input name="username" type="text"><br />';  
	echo 'Password - <input name="password" type="password"><br />';  
	echo '<input name="submit" type="submit" value="Submit"><br />';  
	echo '</form>';  
}  else {
	echo 'You are already logged in!';
}
}  
?>

 

Any help?

 

Link to comment
https://forums.phpfreaks.com/topic/188743-new-cookie-problem/
Share on other sites

The first one:

Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/content/e/q/u/equianadmin/html/htdocs/pages/loginhelp.php on line 58
something failed. who knows.

Line 58 is where i put the mysqli_error();

 

 

The second one:

Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/content/e/q/u/equianadmin/html/htdocs/pages/loginhelp.php on line 31

Notice: in /home/content/e/q/u/equianadmin/html/htdocs/pages/loginhelp.php on line 31

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/e/q/u/equianadmin/html/htdocs/pages/loginhelp.php on line 33
Log in failed

 

Link to comment
https://forums.phpfreaks.com/topic/188743-new-cookie-problem/#findComment-996344
Share on other sites

<?php 

// Set the database access information as constants:
DEFINE ('DB_USER', 'filed');
DEFINE ('DB_PASSWORD', 'out.');
DEFINE ('DB_HOST', 'respectively');
DEFINE ('DB_NAME', '');

// Make the connection:
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
//(this is actually filled out)

if(isset($_COOKIE['username']) || $_COOKIE['password']){  
$username = $_COOKIE['username'];  
$password = $_COOKIE['password'];  

if (isset($_COOKIE['username']) && ($_COOKIE['password'])){  
	echo 'cookie logged in<br />';  
	echo 'Click <a href="logout.php">here</a> to log out';  
}  

}  

if(isset($_POST['submit'])){  //if the form has been submitted


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

if ($result = mysqli_query($dbc, "SELECT COUNT(*) FROM users WHERE username='" . $username . "' AND password='" . $password . "'")) { 
    	$row = mysqli_fetch_assoc($result);  
	  
	 if ($row['COUNT(*)'] == 1) { 

	setcookie("username", $username, time()+3600, "/");  
	setcookie("password", $password, time()+3600, "/");  
	echo 'logged in<br />';  
	echo 'Click <a href="logout.php">here</a> to log out';

	?>

        <script language="javascript">

	window.location = "http://www.liveequian.com/htdocs/pages/login_main.php";

	</script>

	<?php

	} else {   //the username does not match

	echo 'Log in failed';  

	}  

} else {

	mysqli_error($dbc);
	echo 'something failed. who knows.';

}

}  else {   //the form was not submitted 

if(!isset($_COOKIE['username'])){  
	echo '<form action="" method="POST">';  
	echo 'Username - <input name="username" type="text"><br />';  
	echo 'Password - <input name="password" type="password"><br />';  
	echo '<input name="submit" type="submit" value="Submit"><br />';  
	echo '</form>';  
}  else {
	echo 'You are already logged in!';
}
}  
?>

Link to comment
https://forums.phpfreaks.com/topic/188743-new-cookie-problem/#findComment-996356
Share on other sites

Ahh. Duh. Sorry, I haven't dealt too much with mysqli_error. I guess i should be..  ::)

 

So, I figured out what was giving me the original error. Now it's giving me this:

 

"something failed. because You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1something failed. who knows."

<?php 

// Set the database access information as constants:


// Make the connection:
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
//(this is actually filled out)

if(isset($_COOKIE['username']) || $_COOKIE['password']){  
$username = $_COOKIE['username'];  
$password = $_COOKIE['password'];  

if (isset($_COOKIE['username']) && ($_COOKIE['password'])){  
	echo 'cookie logged in<br />';  
	echo 'Click <a href="logout.php">here</a> to log out';  
}  

}  

if(isset($_POST['submit'])){  //if the form has been submitted


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

if ($result = mysqli_query($dbc, "SELECT COUNT(*) FROM users WHERE username='" . $username . "' AND pass=SHA1('$password'))")) { 
    	$row = mysqli_fetch_assoc($result);  
	  
	 if ($row['COUNT(*)'] == 1) { 

	setcookie("username", $username, time()+3600, "/");  
	setcookie("password", $password, time()+3600, "/");  
	echo 'logged in<br />';  
	echo 'Click <a href="logout.php">here</a> to log out';

	?>

        <script language="javascript">

	window.location = "http://www.liveequian.com/htdocs/pages/login_main.php";

	</script>

	<?php

	} else {   //the username does not match

	echo 'Log in failed';  
	echo 'bad because ' . mysqli_error($dbc);

	}  

} else {

	echo 'something failed. because ' . mysqli_error($dbc);
	echo 'something failed. who knows.';

}

}  else {   //the form was not submitted 

if(!isset($_COOKIE['username'])){  
	echo '<form action="" method="POST">';  
	echo 'Username - <input name="username" type="text"><br />';  
	echo 'Password - <input name="password" type="password"><br />';  
	echo '<input name="submit" type="submit" value="Submit"><br />';  
	echo '</form>';  
}  else {
	echo 'You are already logged in!';
}
}  
?>

 

Again, thank you so much, you're being very helpful!

 

Link to comment
https://forums.phpfreaks.com/topic/188743-new-cookie-problem/#findComment-996366
Share on other sites

   
   if ($result = mysqli_query($dbc, "SELECT COUNT(*) FROM users WHERE username='" . $username . "' AND pass=SHA1('$password'))")) { 

should be

   
   if ($result = mysqli_query($dbc, "SELECT COUNT(*) FROM users WHERE username='" . $username . "' AND pass=SHA1('$password')")) { 

Link to comment
https://forums.phpfreaks.com/topic/188743-new-cookie-problem/#findComment-996368
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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