Am am running my php search code and it gives me this error and i have to be done by

Discussion in 'PHP' started by exzevia, Dec 16, 2010.

  1. #1
    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Forum\search.php on line 62

    and here is the code. Sorry for the long code please help.

    <?php
    echo "<table align='center'>";
    echo "<tr>";
    echo "<td>";
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <style type="text/css">
    <!--
    .style24 {font-family:"Times New Roman"; font-size: 10px; color: #000000; }
    .style34 {font-size: 12px; font-family: Arial; }
    .style35 {font-family: Arial; font-weight: bold; font-size: 12px; color: #660000; }
    -->
    </style>
    </head>

    <body>
    <?php
    require ("header.php");
    echo "<table align='center'>";
    echo "<tr>";
    echo "<td>";
    ?>
    <table width="737" cellpadding="0" cellspacing="0">
    <tr>
    <td width="503" height="26" valign="top"><div align="right" class="style35">Enter User ID here&nbsp;</div></td>
    <td width="232" bgcolor="#FFFFFF"><form id="form1" name="form1" method="post" action="file:///G|/search2.php">
    <table width="232" cellpadding="0" cellspacing="0">
    <tr>
    <td width="141" height="24"><input name="searchfield" type="text" class="style34" id="searchfield" /></td>
    <td width="89"><label>
    <input name="Submit" type="submit" class="style34" value="Search" />
    </label></td>
    </tr>
    </table>
    </form></td>
    </tr>
    </table>
    <table width="806" border="1" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td width="802" bordercolor="#990000"><span class="style24"><span class="style34">
    <?php
    $search=$_POST["searchfield"];
    echo "<B>$search";
    $server="localhost";
    $user="root";
    $password="";

    $mysql_con=mysql_connect($server,$user,$password);
    $db="forum";
    $mysqldb=mysql_select_db($db);
    $query=("select * from users = '$search';");
    $result=mysql_query($query);
    echo "<table width='100%' bordercolor='#666666' border='0' cellspacing='2' cellpadding='2' align='center'>";
    echo "<td bgcolor='#E5E5E5',align='center'><font size='2' face='Arial'><b>ID<b/></font></td>";
    echo "<td bgcolor='#E5E5E5', align='center'><font size='2' face='Arial'><b>UserName<b/></font></td>";
    echo "<td bgcolor='#E5E5E5', align='center'><font size='2' face='Arial'><b>Password<b/></font></td>";
    echo "<td bgcolor='#E5E5E5', align='center'><font size='2' face='Arial'><b>E-mail<b/></font></td>";
    while($row=mysql_fetch_array($result))
    {
    $fname=$row["id"];
    $lname=$row["username"];
    $mname=$row["password"];
    $passport=$row["email"];
    if ($counter % 1 !=0){
    echo "<tr bgcolor='#E5E5E5'><td align='center'><font size='2' face='Arial'>$counter</font></td>";
    echo "<td><font size='2' face='Arial'>$fname</font></td>";
    }
    else
    {
    echo "<tr bgcolor='#CCFFCC'>";
    echo "<td><font size='2' face='Arial'>$fname</font></td>";
    echo "<td><font size='2' face='Arial'>$lname</font></td>";
    echo "<td><font size='2' face='Arial'>$mname</font></td>";
    echo "<td><font size='2' face='Arial'>$passport</font></td>";
    }
    $counter++;
    }
    echo "</table>";
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    ?>
    </span></span></td>
    </tr>
    </table>
    </body>
    </html>
    <?php
    require ("footer.php");
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    ?>
     
    exzevia, Dec 16, 2010 IP
  2. goodmast3r

    goodmast3r Active Member

    Messages:
    1,220
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #2
    Your query is probably wrong.

    $query=("select * from users = '$search';");

    echo the $query to see what it is. and try in mysql. Get the right query in mysql and apply it to the code.

    correct query should look like
    select * from users where name = 'xxx'

    You did not supply WHERE
     
    goodmast3r, Dec 16, 2010 IP
  3. exzevia

    exzevia Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks a lot Goodmast3r . my code is now working perfectly . Good tidings to you
     
    exzevia, Dec 16, 2010 IP