Click here to Skip to main content
12,628,919 members (34,603 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: PHP MySQL DataTable
Browser window:
Connected to MySQL
Connected to Database

Notice: Undefined variable: link in C:\xampp\htdocs\globall\members.php on line 23

Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\globall\members.php on line 23


this is line 23
$result = mysql_query($query,$link)

<?php
mysql_connect("localhost", "admin", "") or die(mysql_error());
 
echo "Connected to MySQL<br />";
 
mysql_select_db("globall") or die(mysql_error());
echo "Connected to Database";
 
$query = " SELECT user_name,  mobile " .
        "FROM  customer ";
 

echo  "<br>" ;
 
$result = mysql_query($query,$link)
or die(mysql_error());
 
// this will count the total user in database
$num_users = mysql_num_rows($result);
 
$table_header =<<<EOD
<h2><center>GLoBALL Users Database </center></h2>
 
<table width="100%" border="1" cellpadding="2" cellspacing="2" align="center">
<tr>
<th>Username</th>
<th>Mobile</th>
</tr>
 
EOD;
 
$user_details = '';
 
while ($row = mysql_fetch_array($result)) {
$user_name = $row['user_name'];
$mobile = $row['mobile'];
 
$user_details .=<<<EOD
<tr>
<td>$user_name</td>
<td>$mobile</td>
</tr>
EOD;
 

$user_details .=<<<EOD
<tr>
<td>&nbsp;</td>
<td>Total : $num_users</td>
</tr>
EOD;
}
?>
Posted 21-Mar-12 2:56am
Updated 21-Mar-12 3:10am
v2
Comments
harpuneetthind 21-Mar-12 8:59am
   
I modify my whole code according to W3schools and facing error on this line :
Parse error: syntax error, unexpected '}' in C:\xampp\htdocs\globall\members.php on line 32 which is
}
echo "</table>";



code start here-----


<tr>
<th>Username</th>
<th>Mobile</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row[$user_name]."</td>";
echo "<td>" . $row[$mobile]."</td>";
</tr>"
}
echo "</table>";

mysql_close($con);

?>
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Change the first line of code to
$link=mysql_connect("localhost", "admin", "") or die(mysql_error());

Thanks

Anand Ayyappan
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 26 Mar 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100