0

I am getting this error:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in ?/config.php on line 9

Code:

<!-- Config.php Code -->
    <?php session_start();

    //mysql connection
    $con = mysql_connect("localhost","digmoorc","community20");
    mysql_select_db("digmoorc_EHUB",$con);

    function getUserData($userID) {
        $query=mysql_query("select 'userID' from tbl_users where userID=$userID limit 1");
    while($row = mysql_fetch_array($query))
    if ($query === false) mysql_error();
    {
    }
    }
    ?>
halfer
  • 19,824
  • 17
  • 99
  • 186
  • I also get Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/digmoorc/public_html/www.evermoorhub.co.uk/config.php on line 9 by using the following code. – Daniel Woods Jul 07 '15 at 10:42
  • This line `if(isset($_POST['Submit'])) {` dont have a closing brace anywhere in the file – viral Jul 07 '15 at 10:42
  • You can ask one question at a time, and also you can edit your question body to add more information, no need to add this as a comment. Take a quick [tour here](http://stackoverflow.com/tour) – viral Jul 07 '15 at 10:44
  • Thank You Viral and Markus, the issue that issue has been resolved however i have a new one that has appeared – Daniel Woods Jul 07 '15 at 10:47

2 Answers2

0

In such cases you have to look for missing semicolons at the end of lines and for missing closing brackets.

In this case your first if clause

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

is not closed. So there is no closing }.

Markus F
  • 96
  • 4
0

try this

<?php

    require("config.php");
$error = '';
    if(isset($_POST['Submit'])) {

        $userName=$_POST['userName'];
        $passWord=$_POST['passWord'];

        $query=mysql_query("select user ID from tbl_users where userName='$userName' and passWord='$passWord' limit 1");
    if(mysql_num_rows($query)==1) {
    //login success
    $data=mysql_fetch_array($query,1);
    $_SESSION['userID']=$data['userID'];
    header("location:dashboard.php");
    exit();

    }else{
    //login failed
    $error="Invalid Login";
    }
}

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <html>
    <head>
    <head profile="http://www.w3.org/2005/10/profile">

    <link rel="icon" type="image/png" href="#" />

        <!--META DATA -->
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta http-equiv="Content-Language" content="en" />

        <link rel="credits" type="rel" href="http://www.cultivatecreative.co.uk/" />

        <!-- STYLESHEETS -->
        <style>
        body {
            background: #e8f5f6;
            font-family: Arial, Helvetica, sans-serif;
            font-size: 12px;
            text-rendering: optimizeLegibility;
            font-weight: normal;
            color: #444;
            padding-top: 39px;
            -webkit-tap-highlight-color: #62A9DD;
            }
        #header {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 39px;
            padding: 0;
            background: #59c5c4;
            -moz-box-shadow:inset 0 0 10px #2f6b8f;
            -webkit-box-shadow:inset 0 -5px 10px #2f6b8f;
            box-shadow:inset 0 0 10px #2f6b8f;
            }
        #wrapper {
            width: 540px;
            margin: 100px auto;
            padding: 30px;
            background: #fff;
            }
        a.logo {
            margin: 18px auto 30px;
            display: block;
            width: 244px;
            height: 107px;
            background: url(file:///C|/Users/Daniel/Downloads/Evermore%20HUB/evermoorhub-logo.png) no-repeat;
            text-indent: -9999px;
            border: none;
            }   
        h1 {
            text-align: center;
            font-size: 2.833em; /* 22px */
            font-family: arial, sans-serif;
            color: #444;
            font-weight: normal;
            color: #59c5c4;
            }
        a {
            color: #000;
            text-decoration: none;
        }

        a:hover {
            border-bottom: none;
        }

        p {
            text-align: center;
            font-size: 1em; /* 22px */
            font-family: arial, sans-serif;
            color: #000;
            font-weight: normal;
            color: #000;        
        }
        #wrapper table {
        background-color: #59c5c4;
    }

        </style>

        <title>Evermoor HUB | Login</title>

    </head>

    <body>
    <div id="header"></div>
    <div id="wrapper">
    <a class="logo" href="http://www.evermoorhub.co.uk" title="Webpage design:">Daniel Woods</a>
    <h1><strong><center>User Login</center></strong></h1>
    <form action=""  method="post">
    <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table">
      <?php if(isset($error)); ?>

      <td colspan="2" align="center"><strong class="error"><?php echo $error; ?></strong></td>
      </tr>
        <td width="50%" align="right">Username:</td>
        <td width="50%"><input name="userName" type="text" id="userName"></td>
      </tr>
      <tr>
        <td align="right">Password:</td>
        <td><input type="password" name="passWord" id="passWord"></td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td><input type="submit" name="Submit" id="Submit" value="Submit"></td>
      </tr>
    </table>
    </form>
    </div> <!-- Wrapper -->
    </body>
    </html>
Dhinju Divakaran
  • 893
  • 1
  • 8
  • 11