0

I have a login.html in which the form is defined as follows:

<form method="post" action= "do_authorize.php"  name="lform">
  <span class="style1">First Initial Plus Last Name :</span>  
    <input type="text" name="user" size="25">
    <input type="submit" value="login">
</form>

My do_authorize is as follows:

<?php
session_start();

require('../databaseConnectionFileFolder/dbconnection.php');

$user             = $_POST["user"]; 

var_dump($user);

$_SESSION['username']=$user;

var_dump($user);

$sql="SELECT * FROM $table_name_users WHERE username = \"$user\"";

var_dump($sql);

$result=@mysql_query($sql,$connection) or die("couldn't execute query");

$num=mysql_numrows($result);
if ($num != 0) {

/*$cookie_name="$user";
$cookie_value="ok";
$cookie_expire=time()+86400;
$cookie_domain=".columbia.edu";

setcookie($cookie_name, $cookie_value, $cookie_expire, "/", $cookie_domain, 0);
*/
    print "<script>";
    print "self.location='somethingelse.php';";
    print "</script>";

} else {
echo "<p>you're not authorized";
}


?>

My dbconnection.php file is as follows:

<?php

$db_server      = "localhost"; 
$db_name        = "DailyExerciseDB"; 
$db_user        = "abc5"; //the database username

//$db_password      = "123"; // the database user pasword

$connection=@mysql_connect($db_server,$db_user) or die("Could Not Connect to the Database :   ". mysql_error());
var_dump($connection);
$db=@mysql_select_db($db_name, $connection) or die("Could Not Select the Database". mysqli_connect_error());

//var_dump($db);


?>

My Questions: 1) I keep on getting Could Not Select the Database, why does the warning/error message corresponding to . mysqli_connect_error() doesn't get printed on the browser?

2) I have manually entered the user with username abc5 in the database and still it's not able to connect.Does anyone know why?

3) Even if I don't enter anything in the login.html and press login button, the following files gets executed, how can I take user entered into account while verifying with database? I believe since its hardcoded right now abc5, all files are getting executed.

4) var_dump($connection); prints resource(4, mysql link)

14

1 Answer 1

1

mysql_connect() has a third parameter which I'm not seeing you use: the password. Consider the following line:

mysql_connect($db_server, $db_username, $db_password);

Also, you should probably be using mysqli extension instead of the mysql extension (mysql is deprecated in PHP 5.5.0).

I also see you're mixing the mysql and mysqli functions in your code. This is the reason why mysqli_connect_error() shows nothing.

Sign up to request clarification or add additional context in comments.

1 Comment

The username I have added in the database and I am not sure what password I should be passing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.