Jump to content

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given on line 56 Notice: Undefined va


blackpendant

Recommended Posts

sir can can u fix mine too.? I'm new to this language  : index.php

 

'<link rel="stylesheet" type="text/css" href="css/style.css" />
<?php include('dbcon.php');
include('header.php');
 ?>
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
    
<a class="brand">
<img src="images/chmsc.png" width="60" height="60">
  </a>
<a class="brand">
<h2>SSG ELECTRONIC VOTING SYSTEM</h2>
<div class="chmsc_nav"><font size="4" color="white">Sibonga Community College</font></div>
  </a>


<?php include('head.php'); ?>


</div>
</div>
</div>
<div class="wrapper_admin">
</br>
</br>
</br>
<div id="element" class="hero-body-index">


<p><font color="white"><h2>Admin Login</h2></font></p>


<form method="POST" >
<table>
    <tr><td><font color="white">UserName:</font>  </td><td><input type="text"  name="UserName" class="UserName_hover"></td></tr>
<tr><td>...<td></tr>
    <tr><td><font color="white">Password:</font>  </td><td><input type="Password" name="Password" class="Password_hover"></td></tr>
<tr><td>...<td></tr>
<tr><td></td><td>
<button class="btn btn-primary" name="Login"><i class="icon-ok icon-large"></i> Login</button>
</td></tr>
<tr><td>
</td><tr>
</form>
</table>


</br>
<div class="error">
<?php


if (isset($_POST['Login'])){


$UserName=$_POST['UserName'];
$Password=$_POST['Password'];


$login_query=mysql_query("select * from users where UserName='$UserName' and Password='$Password'");
$row=mysql_fetch_array($login_query);
$f=$row['FirstName'];
$l=$row['LastName'];


if ($count > 0){
session_start();
$_SESSION['id']=$row['User_id'];
$_SESSION['User_Type']=$row['User_Type'];
$type=$row['User_Type'];


mysql_query("INSERT INTO history (data,action,date,user)VALUES('$f $l', 'Login', NOW(),'$type')")or die(mysql_error());




header('location:home.php');
}else{
?>
    <div class="alert alert-error">
    <button class="close" data-dismiss="alert">×</button>
   Please check your UserName and Password
    </div>
<?php } 


}


?> 
</div>
</div>
</br>
</br>
</br>
</br>
</br>


<?php include('footer3.php')?> 
</div>


    </body>


</html>
Edited by .josh
Link to comment
Share on other sites

please use code tags around your code when posting it here, it makes it much easier to read.

 

Your error is coming from the fact that your query is failing. change your query lines to the following to better see what the problem is:

$sql = "select * from users where UserName='$UserName' and Password='$Password'";
$login_query=mysql_query($sql) or die("Query Failed!<br><br>The server Reported the following : <br>".mysql_error()."<br><br> when trying to run : <br>$sql");
$row=mysql_fetch_array($login_query);
Link to comment
Share on other sites

 

please use code tags around your code when posting it here, it makes it much easier to read.

 

Your error is coming from the fact that your query is failing. change your query lines to the following to better see what the problem is:

$sql = "select * from users where UserName='$UserName' and Password='$Password'";
$login_query=mysql_query($sql) or die("Query Failed!<br><br>The server Reported the following : <br>".mysql_error()."<br><br> when trying to run : <br>$sql");
$row=mysql_fetch_array($login_query);

thank you for replying sir, i'll give it a try.. uhmm it works but what will i do sir please help! :confused:  it says..

Query Failed!

 

The server Reported the following : 

No database selected

 

when trying to run : 

select * from users where UserName='admin' and Password='admin

 

Can you Fix this for me sir please.!! :(

Edited by blackpendant
Link to comment
Share on other sites

Make sure first, that you are connected to your database. 

$sql("SELECT * FROM users WHERE UserName = '$UserName' && Password = '$Password'");
$login_query = mysql_query($sql) or die("Query Failed :$sql ".mysql_error());
	
				
$rows = mysql_num_rows($login_query);
if($rows == 1)
{
echo 'you got login';
}
else
{
echo 'you got wrong user and password';
}
Edited by jayson_ph
Link to comment
Share on other sites

It looks like you are probably connecting to mysql in dbcon.php but you aren't actually selecting the database.  Make sure you have a line in your code or include that looks something like this: mysql_select_db('your db name here');

this is my dbcon.php <?php mysql_select_db('anon',mysql_connect('localhost','root','')); ?>

Link to comment
Share on other sites

Split that line up, and add some "or die"s to it so you can find where the problem is:

<?php
$con = mysql_connect('localhost', 'root', '') or die("Can't connect to database");
$db = mysql_select_db('annon', $con) or die("database not found on server, or insufficient permissions set for current account");
?>
Edited by Muddy_Funster
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.