Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

what is mysql_fetch_array() expects parameter 1 to be resour

General discussions related to php

Moderators: macek, egami, gesf

what is mysql_fetch_array() expects parameter 1 to be resour

Postby gdcfrank » Wed Apr 10, 2013 9:13 pm

Please tell me whats wrong with this? im getting error in line 17 & 21, please help.. The purpose of this program is to fetch & display the details of the user from db.

<?php
// Connect to database server
mysql_connect("localhost", "root", "") or die (mysql_error ());

// Select database
mysql_select_db("lms") or die(mysql_error());

// (Line 17) Get data from the database depending on the value of the id in the URL
$strSQL = "SELECT * FROM login WHERE id=" . $_GET["id"];
$rs = mysql_query($strSQL);

// (Line 21) Loop the recordset $rs
while($row = mysql_fetch_array($rs)) {

// Write the data of the person
echo "<dt>Name:</dt><dd>" . $row["name"] . "</dd>";
echo "<dt>Username:</dt><dd>" . $row["username"] . "</dd>";
echo "<dt>Rollno:</dt><dd>" . $row["rollno"] . "</dd>";

}
?>

the displayed error message is:
* Undefined index: id in C:\wamp\www\phploginsession\person.php on line 17
* mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\phploginsession\person.php on line 21
gdcfrank
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Apr 10, 2013 8:40 pm

Re: what is mysql_fetch_array() expects parameter 1 to be re

Postby johnj » Thu Apr 11, 2013 12:13 am

Check if your table has enough records and it is able to pull them. Looks like the query is returning boolean false.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: what is mysql_fetch_array() expects parameter 1 to be re

Postby sandeep605085 » Thu Apr 11, 2013 4:57 am

I guess
the problem is in line number 17 that is id is not defined.
may be id is not posted to this page correctly that why the below query is not working which give again the error at line 21.

$strSQL = "SELECT * FROM login WHERE id=" . $_GET["id"];
User avatar
sandeep605085
New php-forum User
New php-forum User
 
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions

Re: what is mysql_fetch_array() expects parameter 1 to be re

Postby gdcfrank » Thu Apr 11, 2013 5:05 am

Sandeep!
I am glad you found that one! i can understand that too. Can you help me to get rid f th prob? if i remov .$_GET["id"] and give simply id=1 or any other id no...it works perfectly... i know somewhere im going wrong. please help me find that...

sandeep605085 wrote:I guess
the problem is in line number 17 that is id is not defined.
may be id is not posted to this page correctly that why the below query is not working which give again the error at line 21.

$strSQL = "SELECT * FROM login WHERE id=" . $_GET["id"];
gdcfrank
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Apr 10, 2013 8:40 pm

Re: what is mysql_fetch_array() expects parameter 1 to be re

Postby johnj » Thu Apr 11, 2013 8:41 pm

If you id=1 and if it is working that means what ever you have in $_GET["id"] is not present in your database. Please print the SQL query to see why this is going wrong.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: what is mysql_fetch_array() expects parameter 1 to be re

Postby sandeep605085 » Thu Apr 11, 2013 10:21 pm

you must be posting some data to this page. so the posted data is not including any 'id' parameter that is why the value of $_get['id'] is blank. so please check your posted parameters.
OR
if you can post the code here then i can help you for sure to fix the issue by looking at the code(the current page code that is person.php and the page which is calling person.php)
User avatar
sandeep605085
New php-forum User
New php-forum User
 
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions

Re: what is mysql_fetch_array() expects parameter 1 to be re

Postby Nicknnick » Tue Apr 30, 2013 5:03 pm

may be you need to define your id primary key in your database, i am not sure but you can try it..!
Nicknnick
New php-forum User
New php-forum User
 
Posts: 8
Joined: Tue Apr 30, 2013 3:31 pm


Return to PHP General

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

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