mysql - Simple PHP fetch all data in table not working -
ok don't know hell going on i'm trying list data in table , it's not working have tried few different ways , i'm not getting error messages , have been on syntax many times.
here code:
// connect database $dbc = mysql_connect("localhost", "root"); if (!$dbc) die("could not connect" . mysql_error()); // select database $dbc_dbselect = mysql_select_db( "contactmanager", $dbc ); if (!$dbc_contactmanager) die("could not connect: " . mysql_error()); // query database $query = "select * contacts order name"; $result = mysql_query($query); // start table tag in html echo '<table>'; // create loop loop through results while($row = mysql_fetch_array($result)){ // print results echo '<tr>'.'<td>'.$row['name'].'</td>'.'<td>'.$row['address'].'</td>'.'<td>'.$row['phone'].'</td>'.'<td>'.$row['mobile'].'</td>'.'<td>'.$row['mobile'].'</td>'.'</tr>'; } echo "</table>"; //close table in html mysql_close($dbc);
and output result in firefox:
'; //create loop loop through results while($row = mysql_fetch_array($result)){ echo ''.''.$row['name'].''.''.$row['address'].''.''.$row['phone'].''.''.$row['mobile'].''.''.$row['mobile'].''.''; //$row['index'] index here field name } echo ""; //close table in html mysql_close($dbc); ?>
database , table
i think missing third parameter i.e: password
$dbc = mysql_connect("localhost", "root", ""); ^----here
it should be:
mysql_select_db( "contactmanager", $dbc );
Comments
Post a Comment