PLEASE HELP! Cannot access the Databace in MySQL

Codes here !

Moderators: macek, egami, gesf

kelvin24
New php-forum User
New php-forum User
Posts: 12
Joined: Mon Aug 13, 2012 5:11 pm

PLEASE HELP! Cannot access the Databace in MySQL

Postby kelvin24 » Mon Aug 13, 2012 5:26 pm

I'm new to PHP and I'm seeking for your help. I have watched some tutorial about displaying MySQL tables in html and I've done exactly what it does but still it didn't display the tables. What's wrong with my code?
:help:

Code: Select all

<?php
$con = mysql_connect("localhost","root","kelvin");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("softeng");
$sql = "SELECT * FROM records WHERE Referrence No = '37-IICF-2011-06' ";
$myData = mysql_query($sql,$con);
echo "<table border=1>
<tr>
   
   <th>Referrence No</th>
   <th>Date</th>
   <th>Dealer</th>
</tr>";
while($record = mysql_fetch_array($myData)){
echo "<tr>";
echo "<td>" . $record['Referrence No'] . "</td>";
echo "<td>" . $record['Date'] . "</td>";
echo "<td>" . $record['Dealer'] . "</td>";
echo "</tr>";

}



echo "</table>";


mysql_close($con);
Attachments
OUTPUT IMAGE.jpg
This is what happens when I run the code
OUTPUT IMAGE.jpg (46.52 KiB) Viewed 677 times

User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 285
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: PLEASE HELP! Cannot access the Databace in MySQL

Postby freshnet » Tue Aug 14, 2012 2:38 am

This looks like a problem with your quotes rather than anything else. Try referencing the fields by number and using single quotes, e.g.

Code: Select all

echo '<td>' . $record[0] . '</td>';

kathirsrs
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Jul 25, 2012 10:45 pm

Re: PLEASE HELP! Cannot access the Databace in MySQL

Postby kathirsrs » Tue Aug 14, 2012 4:10 am

Hi,

The same code works fine in my system.So please check with DB name and SQL connection.

kelvin24
New php-forum User
New php-forum User
Posts: 12
Joined: Mon Aug 13, 2012 5:11 pm

Re: PLEASE HELP! Cannot access the Databace in MySQL

Postby kelvin24 » Tue Aug 14, 2012 8:09 am

kathirsrs wrote:Hi,

The same code works fine in my system.So please check with DB name and SQL connection.



The DB is correct. How will I know if the connection is correct?

User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 285
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: PLEASE HELP! Cannot access the Databace in MySQL

Postby freshnet » Tue Aug 14, 2012 8:58 am

The connection is not the issue, as you have that error trapped. Notice in your output that instead of outputting nothing, it outputs the name of your variables. It's like it's treating the code there as not php. Maybe also make sure that you have an ending php ?> (I know that's not required but still worth checking).

User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 285
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: PLEASE HELP! Cannot access the Databace in MySQL

Postby freshnet » Tue Aug 14, 2012 9:00 am

I also see two ?> in your output. I'm thinking that you may have closed your php block prematurely. Please post the entire code for that page.

kelvin24
New php-forum User
New php-forum User
Posts: 12
Joined: Mon Aug 13, 2012 5:11 pm

Re: PLEASE HELP! Cannot access the Databace in MySQL

Postby kelvin24 » Tue Aug 14, 2012 6:08 pm

Thanks for all your help Guys!

kelvin24
New php-forum User
New php-forum User
Posts: 12
Joined: Mon Aug 13, 2012 5:11 pm

Re: PLEASE HELP! Cannot access the Databace in MySQL

Postby kelvin24 » Tue Aug 14, 2012 9:58 pm

I need a little help I tried using to use <td width='250px'> to edit the width of table row but nothing happened. This is my code.

Code: Select all

<?php
$username = "root";
$password = "kelvin";
$hostname = "localhost";

$dbhandle = @mysql_connect($hostname, $username, $password) or die("Could not connect to database");
@mysql_select_db("softeng", $dbhandle) or die("No database");
$sql = "SELECT * FROM records";
$myData = @mysql_query($sql,$dbhandle) or die ("Can not fetch data");
echo "<center><table border=1>
<tr>
   
   <th>Referrence No</th>
   <th>Date</th>
   <th>Dealer</th>
   <th>Repair Order</th>
   <th>Parts Issuance Slip</th>
   <th>Service Invoice</th>
   <th>Engine Oil Type</th>
   <th>No of Liters Sold</th>
   <th>Servive Advisor/Parts Man</th>
   <th>Incentive Amount</th>
   <th>Technician</th>
   <th>Incentive Amount</th>
   <th>Service Manager</th>
   <th>Incentive Amount</th>
   <th>Parts Manager</th>
   <th>Incentive Amount</th>
   <th>Total Amount</th>
   
</tr>";
while($record = @mysql_fetch_array($myData)){
echo "<tr>";
echo "<td>" . $record['Referrence No'] . "</td>";
echo "<td>" . $record['Date'] . "</td>";
echo "<td>" . $record['Dealer'] . "</td>";
echo "<td>" . $record['Repair Order'] . "</td>";
echo "<td>" . $record['Parts Issuance Slip'] . "</td>";
echo "<td>" . $record['Service Invoice'] . "</td>";
echo "<td>" . $record['Engine Oil Type'] . "</td>";
echo "<td>" . $record['No of Liters Sold'] . "</td>";
echo "<td>" . $record['Service Advisor/Parts Man'] . "</td>";
echo "<td>" . $record['Incentive_SAPM'] . "</td>";
echo "<td>" . $record['Technician'] . "</td>";
echo "<td>" . $record['Incentive_Tech'] . "</td>";
echo "<td>" . $record['Service Manager'] . "</td>";
echo "<td>" . $record['Incentive_SM'] . "</td>";
echo "<td>" . $record['Parts Manager'] . "</td>";
echo "<td>" . $record['Incentive_PM'] . "</td>";
echo "<td>" . $record['Total Amount'] . "</td>";



echo "</tr>";

}



echo '</table></center>';


mysql_close($con);




?>
 </div></center>
Attachments
tablerow.png
tablerow.png (55.19 KiB) Viewed 625 times

User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 285
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: PLEASE HELP! Cannot access the Databace in MySQL

Postby freshnet » Thu Aug 16, 2012 7:02 am

You should change the cell width with css for the page, rather than with attributes on the individual element, e.g.

Code: Select all

td {width: 250px;}


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest