Anita Coertez
asked on
How to remove these errors in my system? Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\cman\admin\login_admin.php on line 29 Warning: mysqli_num_rows() expects par
login_admin.php
<?php
include('dbconn.php');
?>
<form id="login_form1" class="form-signin" method="post">
<h3 class="form-signin-heading">
<i class="icon-lock"></i> Administrator Login
</h3>
<input type="text" class="input-block-level" id="username" name="username" placeholder="Username" required>
<input type="password" class="input-block-level" id="password" name="password" placeholder="Password" required>
<button data-placement="right" title="Click Here to Sign In" id="signin" name="login" class="btn btn-info" type="submit"><i class="icon-signin icon-large"></i> Sign in</button>
<script type="text/javascript">
$(document).ready(function(){
$('#signin').tooltip('show');
$('#signin').tooltip('hide');
});
</script>
</form>
</br>
<div class="error">
<?php
if (isset($_POST['login'])){
$username=$_POST['username'];
$password=$_POST['password'];
$login_query=mysqli_query("select * from admin where username='$username' and password='$password'");
$count=mysqli_num_rows($login_query);
$row=mysqli_fetch_array($login_query);
if ($count > 0){
session_start();
$_SESSION['id']=$row['admin_id'];
header('location:dashboard.php');
}else{
header('location:index.php');
}
}
?>
</div>
Can you post a URL or place your code between the code brackets?
I've addressed this specific problem in your previous question, Anita. It's just that you need to pass the database link as the first parameter to your mysqli_query call.
Please make sure you follow all of my suggestions in that other post, since they apply here, too (SQL injection, session_start() location, exiting after header("Location:..."), etc...)
Please make sure you follow all of my suggestions in that other post, since they apply here, too (SQL injection, session_start() location, exiting after header("Location:..."), etc...)
@gr8gonzo so the info dbconn.php needs to be included in the query?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In simple word you are missing connection string
example:
Regards
Mohan Singh
example:
$conn = mysql_connect('databasName','userName',password');
// And your query should be like this
$sql = mysqli_query($conn, "SELECT * FROM yourTable");
//OR also you can use
$sql = "SELECT * FROM yourTable";
$result = mysqli_query($conn);
Thank YouRegards
Mohan Singh
@mohan - Please read previous comments before suggesting to make sure you're not suggesting the same thing, and also try your code before suggesting it, unless you are absolutely certain it works. As it stands, you are not adding anything new and none of your code works:
1. You use mysql_connect() instead of mysqli_connect(), so not only will $conn be the wrong type for mysqli_query, but you're suggesting a deprecated mysql_ function.
2. Your "OR also you can use" simply will not work at all because you're not passing the query as a parameter, so mysqli_query($conn) will not know what query to execute.
3. The term "connection string" does not apply to this situation. The mysqli extension does not use connection strings. Connection strings are used in generic connectors, like ODBC.
1. You use mysql_connect() instead of mysqli_connect(), so not only will $conn be the wrong type for mysqli_query, but you're suggesting a deprecated mysql_ function.
2. Your "OR also you can use" simply will not work at all because you're not passing the query as a parameter, so mysqli_query($conn) will not know what query to execute.
3. The term "connection string" does not apply to this situation. The mysqli extension does not use connection strings. Connection strings are used in generic connectors, like ODBC.
OK I Understand
Thank You
Thank You
All member give same answer but gr8gonzo give first