# Error when trying to retrieve SQL data

**URL:** <https://forum.kirupa.com/t/error-when-trying-to-retrieve-sql-data/129584>\
**Category:** Uncategorized\
**Created:** [November 25, 2004, 8:44am UTC](https://forum.kirupa.com/t/error-when-trying-to-retrieve-sql-data/129584 "2004-11-25T08:44:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mprzybylski](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mprzybylski/32/613_2.png) [@mprzybylski](https://forum.kirupa.com/u/mprzybylski)\
**Post date:** [November 25, 2004, 8:44am UTC](https://forum.kirupa.com/t/error-when-trying-to-retrieve-sql-data/129584/1 "2004-11-25T08:44:23Z")

</div>

I have the following code in a php file on my server:

```php
<?
$server = "localhost";
$username = "reintro_matt";
$password = " *******";
$database = "reintro_testdb";
$table = "ecard";

//connect to database
$connection = mysql_pconnect($server, $username, $password) or die ("Couldn't connect to the database.");
$selection = mysql_select_db($database) or die ("No database selected.");
	
//make query
$sql = "SELECT * FROM '" . $table ."'";
$result = mysql_query($sql);
$nrows = mysql_num_rows($result);
if($nrows != 0)
{
	print "<p>Data for " . $table;
	print "<table border=2><tr><th>Name<th>Email
";
	for($j=0;$j<$nrows;$j++)
	{
		$row = mysql_fetch_array($result);
		print "<tr><td>" . $row["from_name"];
		print "<td>" . $row["from_email"];
		print "
";
	}
	print "</table>
";
}
else	print "<p>No Entry for " . $table;
mysql_close($connection);

if ($connection) {
   $msg = "success!";
}
if ($selection) {
   $msg2 = "selected!";
}

?>

<html>
<head>
<title>Did I get in?</title>
</head>

<body>

<br><br>

<? echo "$msg"; ?><br>
<? echo "$msg2"; ?>

</body>
</html>

```

the output can be viewed here:

[http://www.reintroducing.com/play/query\_test2.php](http://www.reintroducing.com/play/query_test2.php)

the connection to the database is successful but it’s giving me that error and it’s not displaying the row of data that i have in my table. any idea what might be the problem?

i’m a newbie to PHP so any help is greatly appreciated. thanks in advance.
