Help needed Warning: mysql_fetch_array()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
patison13
Forum Newbie
Posts: 2
Joined: Thu Nov 19, 2009 5:52 pm

Help needed Warning: mysql_fetch_array()

Post by patison13 »

Hi,
Im a newbie with PHP and mysql. I am doing or trying to do the code to retrieve data from the database where user input a name to search. I am getting Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\system\search_name.php on line 14 but i really could not find the mistake myself. Please help. This is my code:

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("login_password_manager", $con);

$tempname=$_POST["tempname"];

$result=mysql_query("SELECT (Name, Username, Password, Website) FROM login_details WHERE Name LIKE '%$tempname%'");

while($row1=mysql_fetch_array($result))
{
$Name = $row1["Name"];
$Username = $row1["Username"];
$Password = $row1["Password"];
$Website = $row1["Website"];

echo "$Name <br> $Username <br> $Password <br> $Website <br>";

};


mysql_close($con);
?>

I would be grateful for any comments,
thanks
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: Help needed Warning: mysql_fetch_array()

Post by Weiry »

Try changing your SQL to this:
$result=mysql_query("SELECT `Name`, `Username`, `Password`, `Website` FROM `login_details` WHERE `Name` LIKE '%{$tempname}%'");

Also please when posting, wrap your code using the [syntax=php][/syntax] or [syntax=php][/syntax] tags.
patison13
Forum Newbie
Posts: 2
Joined: Thu Nov 19, 2009 5:52 pm

Re: Help needed Warning: mysql_fetch_array()

Post by patison13 »

Love you,
thanks very much. Its working now :D
Post Reply