Jump to content

[SOLVED] Checking if I got in my db table


jmr3460

Recommended Posts

I just inserted this code into my script and it echoed "i got in"

//connect to server and select database
$host = 'localhost';
$username = 'simplic5_jmr3460';
$password = 'freedom98714';
$database ='simplic5_users';
$mysql = mysql_connect($host, $username, $password);
mysql_select_db($database);
//$mysqli = mysql_connect("$host", "$username","$password","simplic5_users");
if ($mysql){
echo "I got in.";
} else {
echo "Not a chance.";
};

 

Does this mean I got in?

Link to comment
Share on other sites

No, I think it just means $mysql isn't NULL, and you assigned it up above.

 

If you don't get in you'll get an error, if you add error to the end of the command, it will display an error if the connection fails, like this:

 

$mysql = mysql_connect($host, $username, $password) or die ('Error connecting to database');

mysql_select_db($database);

Link to comment
Share on other sites

I tried the or die and it still tells me I got in.

So if I got in then why can't I retrieve anything from my user database.

<?php
//check for required fields from the form
if ((!isset($_POST["username"])) || (!isset($_POST["password"]))) {
header("Location: index.html");
exit;
}

//connect to server and select database
$host = 'localhost';
$username = 'simplic5_jmr3460';
$password = 'freedom98714';
$database ='simplic5_users';
$mysql = mysql_connect($host, $username, $password, $database);
mysql_select_db($database);
//$mysqli = mysql_connect("$host", "$username","$password","simplic5_users");


//create and issue the query
$sql = "SELECT f_name, l_name FROM auth_users WHERE username = '".$_POST["username"]."' AND password = PASSWORD('".$_POST["password"]."')";
$result = mysql_query($sql) or die(mysql_error($mysql, $sql, $result));

//get the number of rows in the result set; should be 1 if a match
if (mysql_num_rows($result) == 1) {

//if authorized, get the values of f_name l_name
while ($info = mysql_fetch_array($result)) {
	$f_name = stripslashes($info['f_name']);
	$l_name = stripslashes($info['l_name']);
}

//set authorization cookie
setcookie("auth", "1", 0, "/", "localhost", 0);

//create display string
$display_block = "
<p>".$f_name." ".$l_name." is authorized!</p>
<p>Authorized Users' Menu:</p>
<ul>
<li><a href=\"secretpage.php\">secret page</a></li>
</ul>";
} else {
//redirect back to login form if not authorized
header("Location: index.html");
exit;
}
?>
<html>
<head>
<title>User Login</title>
</head>
<body>
<?php echo "$display_block"; ?>
</body>
</html>


When I open this file It goes to the redirect after the else statement.

Link to comment
Share on other sites

The script seems to not be setting the cookie. Can someone help with this?

The script has the cookie as follows:

setcookie("auth", "1", time()=3600, "/", "whatever.com", 0);

When I check for this cookie not in the list. I have changed whatever.com with my domain. I understand the setcookie(name of cookie, value of cookie, expiration time,directory cookie is set for, domain cookie is set for, security setting)

 

Why is this cookie not setting?

 

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.