Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

mysql_fetch_array() expects parameter 1 to be resource, bool

General discussions related to php

Moderators: macek, egami, gesf

mysql_fetch_array() expects parameter 1 to be resource, bool

Postby JennyH » Mon Aug 20, 2012 11:09 pm

Hello,
I have got an error when i run this code.My query is updated but when I fetch the query then i got this error
mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\html-contact-form-captcha\update.php on line 44

please check the code is given below:-

****

Code: Select all
 <!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=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <table border="1">
    <tr>
    <th> Name</th>
    <th> Active</th>
    <th> Last Name</th>
    </tr>
    <?php
    $id=$_POST['id'];
    $name=$_POST['name'];
    $active=$_POST['active'];
    $lastName=$_POST['lastName'];
    $db=mysql_connect("localhost","root","");
    mysql_select_db("new",$db);
    echo $qry="update records set name='$name', active='$active', LastName='$lastName' where id='$id' ";
    $result=mysql_query($qry);
    while($row=mysql_fetch_array($result)){
    echo"<tr>
    <td>".$row['name']."</td>
    <td>".$row['active']."</td>
    <td>".$row['LastName']."</td>
    </tr>";
    }
    echo mysql_error();
    ?>
    </table>
    </body>
    </html>


****

Please solve this issue asap...thanks in advance..
JennyH
New php-forum User
New php-forum User
 
Posts: 12
Joined: Wed Nov 30, 2011 2:28 am

Re: mysql_fetch_array() expects parameter 1 to be resource,

Postby Acesystech » Mon Aug 20, 2012 11:54 pm

hi jenny.... :)

Try this one



<?php $hostname = 'localhost'; // MySQL hostname.
$username = 'root'; // Database username.
$password = ''; // Database password.

$dbname = 'new'; // Database name.
mysql_connect("$hostname", "$username", "$password")or die("cannot connect");
mysql_select_db("$dbname")or die("cannot select DB");

$id=$_POST['id'];
$name=$_POST['name'];
$active=$_POST['active'];
$lastName=$_POST['lastName'];

$qry="UPDATE records SET name='$name', active='$active', LastName='$lastName' WHERE id='$id' ";
$result=mysql_query($qry);?>

<!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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table border="1">
<tr>
<th> Name</th>
<th> Active</th>
<th> Last Name</th>
</tr>
<?php
while($row=mysql_fetch_array($result)){
echo"<tr>
<td>".$row['name']."</td>
<td>".$row['active']."</td>
<td>".$row['LastName']."</td>
</tr>";
}
echo mysql_error();
?>
</table>
</body>
</html>
Last edited by Acesystech on Tue Aug 21, 2012 12:38 am, edited 1 time in total.
Acesystech
New php-forum User
New php-forum User
 
Posts: 35
Joined: Mon Aug 20, 2012 10:27 pm
Location: Ernakulam

Re: mysql_fetch_array() expects parameter 1 to be resource,

Postby NigelRen » Mon Aug 20, 2012 11:58 pm

There are a couple of things you should do. Always check if mysql_query works...
Code: Select all
if ( $result == false ) {
   // Something which reports errors or whatever you want to do
}


Not sure why you have the echo on
Code: Select all
echo $qry =...

probably best to remove it.

But the main thing is that mysql_fetch_array is used for fetching the results from a select query - not an update.
NigelRen
php-forum Active User
php-forum Active User
 
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am


Return to PHP General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.