blackpendant Posted July 18, 2013 Share Posted July 18, 2013 (edited) 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 July 20, 2013 by .josh Quote Link to comment https://forums.phpfreaks.com/topic/280277-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-on-line-56-notice-undefined-va/ Share on other sites More sharing options...
PravinS Posted July 18, 2013 Share Posted July 18, 2013 (edited) verify your SELECT query by executiig it in phpmyadmin Edited July 18, 2013 by PravinS Quote Link to comment https://forums.phpfreaks.com/topic/280277-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-on-line-56-notice-undefined-va/#findComment-1441218 Share on other sites More sharing options...
Muddy_Funster Posted July 18, 2013 Share Posted July 18, 2013 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); Quote Link to comment https://forums.phpfreaks.com/topic/280277-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-on-line-56-notice-undefined-va/#findComment-1441219 Share on other sites More sharing options...
blackpendant Posted July 20, 2013 Author Share Posted July 20, 2013 (edited) verify your SELECT query by executiig it in phpmyadmin thank you for replying... but Sir i dont know how to excute, please tell me how, Edited July 20, 2013 by blackpendant Quote Link to comment https://forums.phpfreaks.com/topic/280277-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-on-line-56-notice-undefined-va/#findComment-1441468 Share on other sites More sharing options...
blackpendant Posted July 20, 2013 Author Share Posted July 20, 2013 (edited) 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! 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 July 20, 2013 by blackpendant Quote Link to comment https://forums.phpfreaks.com/topic/280277-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-on-line-56-notice-undefined-va/#findComment-1441469 Share on other sites More sharing options...
Yohanne Posted July 20, 2013 Share Posted July 20, 2013 (edited) 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 July 20, 2013 by jayson_ph Quote Link to comment https://forums.phpfreaks.com/topic/280277-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-on-line-56-notice-undefined-va/#findComment-1441473 Share on other sites More sharing options...
.josh Posted July 20, 2013 Share Posted July 20, 2013 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'); Quote Link to comment https://forums.phpfreaks.com/topic/280277-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-on-line-56-notice-undefined-va/#findComment-1441500 Share on other sites More sharing options...
blackpendant Posted July 27, 2013 Author Share Posted July 27, 2013 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','')); ?> Quote Link to comment https://forums.phpfreaks.com/topic/280277-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-on-line-56-notice-undefined-va/#findComment-1442363 Share on other sites More sharing options...
Muddy_Funster Posted July 30, 2013 Share Posted July 30, 2013 (edited) 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 July 30, 2013 by Muddy_Funster Quote Link to comment https://forums.phpfreaks.com/topic/280277-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given-on-line-56-notice-undefined-va/#findComment-1442646 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.