<html>
<head>
</head>
<body>

<table border='1'>
<tr>
<th>Agent_ID</th>
<th>Address</th>
<th>Bedrooms</th>
<th>Price</th>
<?php
$connect=mysql_connect("localhost","root","");

mysql_select_db("ong_assesment',$connect);
$query = mysql_query (SELECT Agent_ID,Address/Suburb,Bedrooms/Bathrooms,Price FROM suburbs);

{
echo '<tr>';
echo '<td>'. $row[Agent_ID].'</td>';
echo '<td>'. $row[Address].'</td>';
echo '<td>'. $row[Bedrooms].'</td>';
echo '<td>'. $row[Price].'</td>';

echo '</table>'
mysql_close();
}
?php>
</body>
</html>

Dani AI

Generated

Thread summary and practical fixes (concise)

This thread shows three common, related problems: a parse error (unexpected $end), a failing database selection / empty result, and "undefined constant" notices when printing row values. fixed most of the syntax mistakes and correctly pointed out the SELECT vs affected-rows issue. The items below are concentrated, actionable steps and a safer example using modern APIs.

Quick debugging checklist

  • "unexpected $end" usually means an unclosed string, missing semicolon, or an unmatched brace/parenthesis. Run a quick syntax check from the command line:
    php -l path/to/file.php
  • Turn on full errors while developing:
    ini_set('display_errors',1); error_reporting(E_ALL);
  • Use <?php to open PHP blocks (avoid short tags unless explicitly enabled). Check every if, while, { and } for balance.
  • "No database selected" means select_db failed (wrong name or connection). Confirm the DB name and connection. For SELECT queries, use mysql_num_rows (or the equivalent) to detect empty result sets, not mysql_affected_rows.
  • Column names with special characters (like Address/Suburb) are fragile — rename them or quote with backticks, or use aliases in the SQL.

Safer, modern approach (use PDO or mysqli, not deprecated mysql_*):

<?php
$pdo = new PDO('mysql:host=127.0.0.1;dbname=ong_assessment;charset=utf8mb4','root','',[
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);

$stmt = $pdo->query('SELECT agent_id, address, bedrooms, price FROM suburbs');
$rows = $stmt->fetchAll();

if (empty($rows)) {
  echo '<p>No entries in the database.</p>';
} else {
  echo '<table border="1"><tr><th>Agent</th><th>Address</th><th>Beds</th><th>Price</th></tr>';
  foreach ($rows as $r) {
    echo '<tr><td>'.htmlspecialchars($r['agent_id']).'</td><td>'.htmlspecialchars($r['address']).'</td><td>'.htmlspecialchars($r['bedrooms']).'</td><td>'.htmlspecialchars($r['price']).'</td></tr>';
  }
  echo '</table>';
}

Linking PHP and HTML / deployment notes
A PHP page is linked the same way as HTML, but it must be served by the web server. With XAMPP put files under F:\xampp\htdocs\ (or an htdocs subfolder) and visit http://localhost/YourFolder/Farcourts.php. Opening the file with a file:// URL will not execute PHP. Also, migrate away from mysql_* (removed in PHP 7+) and always escape output (htmlspecialchars) and use prepared statements when there is user input.

Recommended Answers

All 35 Replies

Member Avatar for Member #120589

change to

echo '</table>';

diafol:still the same

write ?> not ?php>

neha jaltare:still the same

Try this, bit different to your script.. Have a look at yours, you have many errors:

<html>
<head>
</head>
<body>

<table border='1'>
<tr>
<th>Agent_ID</th>
<th>Address</th>
<th>Bedrooms</th>
<th>Price</th>
<?php
$connect=mysql_connect("localhost","root","");

mysql_select_db("ong_assesment",$connect);
$query = "SELECT Agent_ID,Address/Suburb,Bedrooms/Bathrooms,Price FROM suburbs";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result))
{
    echo '<tr>';
    echo '<td>'. $row[Agent_ID].'</td>';
    echo '<td>'. $row[Address].'</td>';
    echo '<td>'. $row[Bedrooms].'</td>';
    echo '<td>'. $row[Price].'</td>';
}
    echo '</table>';

?>
</body>
</html>

e.g. in yours you have:

mysql_select_db("ong_assesment',$connect);

should be:

mysql_select_db("ong_assesment",$connect);

Hope this helps

yes it work but the database not showing

Member Avatar for Member #120589

WHat editor / IDE are you using? Some editors can spot these errors for you, highlighting the problem lines.

Is there an error showing? Is there anything in the table?

it came out table but no data.
message:No database selected

I don't think you're understanding me.. I asked is there an error message showing, NOT what text editor you're using... Ok, try this:

<html>
<head>
</head>
<body>

<table border='1'>
<tr>
<th>Agent_ID</th>
<th>Address</th>
<th>Bedrooms</th>
<th>Price</th>
<?php
$connect=mysql_connect("localhost","root","");

mysql_select_db("ong_assesment",$connect);
$query = "SELECT Agent_ID,Address/Suburb,Bedrooms/Bathrooms,Price FROM suburbs";
$result = mysql_query($query) or die(mysql_erro());

if(!mysql_affected_rows() >= 1)
{
    echo 'There are no entries inside the database';
}
while($row = mysql_fetch_array($result))
{
    echo '<tr>';
    echo '<td>'. $row[Agent_ID].'</td>';
    echo '<td>'. $row[Address].'</td>';
    echo '<td>'. $row[Bedrooms].'</td>';
    echo '<td>'. $row[Price].'</td>';
}
    echo '</table>';

?>
</body>
</html>

Do you get the output: There are no entries inside the database? OR do you get something else?

Is there a database called "ong_assesment"

i got no databse selected

yes. that is my database name

Ok, try this:

where you have:

mysql_select_db("ong_assesment",$connect);

change it to:

$db_selected = mysql_select_db("ong_assesment", $connect);

Making sure, your database name is called "ong_assesment".

Parse error: syntax error, unexpected T_VARIABLE in F:\xampp\htdocs\movies4.php on line 14

Now you have to insert data, for the data to be shown :) Do you use mysqladmin? If so, you can just throw some example data in just to test!

but i already insert data in

Please post your script, how it looks now.. Removing any passwords etc..

<head>
</head>
<body>
<table border='1'>
<tr>
<th>Agent_ID</th>
<th>Address</th>
<th>Bedrooms</th>
<th>Price</th>
<?php
$connect=mysql_connect("localhost","root","");
$db_selected = mysql_select_db("ong_assessment", $connect)
$query = "SELECT Agent_ID,Address,Bedrooms,Price FROM suburbs";
$result = mysql_query($query) or die(mysql_error());
if(!mysql_affected_rows() >= 1)
{
echo 'There are no entries inside the database';
}
while($row = mysql_fetch_array($result))
{
 echo 'There are no entries inside the database';
}
while($row = mysql_fetch_array($result))
{
echo '<tr>';
echo '<td>'. $row[Agent_ID].'</td>';
echo '<td>'. $row[Address].'</td>';
echo '<td>'. $row[Bedrooms].'</td>';
echo '<td>'. $row[Price].'</td>';
}
echo '</table>';
?>
</body>
</html>

LOOK at the syntax..

<head>
</head>
<body>
<table border='1'>
<tr>
<th>Agent_ID</th>
<th>Address</th>
<th>Bedrooms</th>
<th>Price</th>
<?php
$connect=mysql_connect("localhost","root","");
$db_selected = mysql_select_db("ong_assessment", $connect);
$query = "SELECT Agent_ID,Address,Bedrooms,Price FROM suburbs";
$result = mysql_query($query) or die(mysql_error());
if(!mysql_affected_rows() >= 1)
{
echo 'There are no entries inside the database';
}

while($row = mysql_fetch_array($result))
{
echo '<tr>';
echo '<td>'. $row[Agent_ID].'</td>';
echo '<td>'. $row[Address].'</td>';
echo '<td>'. $row[Bedrooms].'</td>';
echo '<td>'. $row[Price].'</td>';
}
echo '</table>';
?>
</body>
</html>

Now, if the output is: 'There are no entries inside the database' then there are no records in the table 'suburbs'. There are NO errors now, don't create errors for yourself.

ok thank you. i will try it now.

Yes, your script is wrong. I posted an altered version the script that fixed the errors you had.

Notice: Use of undefined constant Agent_ID - assumed 'Agent_ID' in F:\xampp\htdocs\movies4.php on line 23

Notice: Use of undefined constant Address - assumed 'Address' in F:\xampp\htdocs\movies4.php on line 24

Notice: Use of undefined constant Bedrooms - assumed 'Bedrooms' in F:\xampp\htdocs\movies4.php on line 25

Notice: Use of undefined constant Price - assumed 'Price' in F:\xampp\htdocs\movies4.php on line 26

Notice: Use of undefined constant Agent_ID - assumed 'Agent_ID' in F:\xampp\htdocs\movies4.php on line 23

Notice: Use of undefined constant Address - assumed 'Address' in F:\xampp\htdocs\movies4.php on line 24

Notice: Use of undefined constant Bedrooms - assumed 'Bedrooms' in F:\xampp\htdocs\movies4.php on line 25

Notice: Use of undefined constant Price - assumed 'Price' in F:\xampp\htdocs\movies4.php on line 26

Notice: Use of undefined constant Agent_ID - assumed 'Agent_ID' in F:\xampp\htdocs\movies4.php on line 23

Notice: Use of undefined constant Address - assumed 'Address' in F:\xampp\htdocs\movies4.php on line 24

Notice: Use of undefined constant Bedrooms - assumed 'Bedrooms' in F:\xampp\htdocs\movies4.php on line 25

Notice: Use of undefined constant Price - assumed 'Price' in F:\xampp\htdocs\movies4.php on line 26

Notice: Use of undefined constant Agent_ID - assumed 'Agent_ID' in F:\xampp\htdocs\movies4.php on line 23

Notice: Use of undefined constant Address - assumed 'Address' in F:\xampp\htdocs\movies4.php on line 24

Notice: Use of undefined constant Bedrooms - assumed 'Bedrooms' in F:\xampp\htdocs\movies4.php on line 25

Notice: Use of undefined constant Price - assumed 'Price' in F:\xampp\htdocs\movies4.php on line 26

Notice: Use of undefined constant Agent_ID - assumed 'Agent_ID' in F:\xampp\htdocs\movies4.php on line 23

Notice: Use of undefined constant Address - assumed 'Address' in F:\xampp\htdocs\movies4.php on line 24

Notice: Use of undefined constant Bedrooms - assumed 'Bedrooms' in F:\xampp\htdocs\movies4.php on line 25

Notice: Use of undefined constant Price - assumed 'Price' in F:\xampp\htdocs\movies4.php on line 26

Notice: Use of undefined constant Agent_ID - assumed 'Agent_ID' in F:\xampp\htdocs\movies4.php on line 23

Notice: Use of undefined constant Address - assumed 'Address' in F:\xampp\htdocs\movies4.php on line 24

Notice: Use of undefined constant Bedrooms - assumed 'Bedrooms' in F:\xampp\htdocs\movies4.php on line 25

Notice: Use of undefined constant Price - assumed 'Price' in F:\xampp\htdocs\movies4.php on line 26

Notice: Use of undefined constant Agent_ID - assumed 'Agent_ID' in F:\xampp\htdocs\movies4.php on line 23

Notice: Use of undefined constant Address - assumed 'Address' in F:\xampp\htdocs\movies4.php on line 24

Notice: Use of undefined constant Bedrooms - assumed 'Bedrooms' in F:\xampp\htdocs\movies4.php on line 25

Notice: Use of undefined constant Price - assumed 'Price' in F:\xampp\htdocs\movies4.php on line 26

Notice: Use of undefined constant Agent_ID - assumed 'Agent_ID' in F:\xampp\htdocs\movies4.php on line 23

Notice: Use of undefined constant Address - assumed 'Address' in F:\xampp\htdocs\movies4.php on line 24

Notice: Use of undefined constant Bedrooms - assumed 'Bedrooms' in F:\xampp\htdocs\movies4.php on line 25

Notice: Use of undefined constant Price - assumed 'Price' in F:\xampp\htdocs\movies4.php on line 26

Notice: Use of undefined constant Agent_ID - assumed 'Agent_ID' in F:\xampp\htdocs\movies4.php on line 23

Notice: Use of undefined constant Address - assumed 'Address' in F:\xampp\htdocs\movies4.php on line 24

Notice: Use of undefined constant Bedrooms - assumed 'Bedrooms' in F:\xampp\htdocs\movies4.php on line 25

Notice: Use of undefined constant Price - assumed 'Price' in F:\xampp\htdocs\movies4.php on line 26

Notice: Use of undefined constant Agent_ID - assumed 'Agent_ID' in F:\xampp\htdocs\movies4.php on line 23

Notice: Use of undefined constant Address - assumed 'Address' in F:\xampp\htdocs\movies4.php on line 24

Notice: Use of undefined constant Bedrooms - assumed 'Bedrooms' in F:\xampp\htdocs\movies4.php on line 25

Notice: Use of undefined constant Price - assumed 'Price' in F:\xampp\htdocs\movies4.php on line 26

<head>
</head>
<body>
<table border='1'>
<tr>
<th>Agent_ID</th>
<th>Address</th>
<th>Bedrooms</th>
<th>Price</th>
<?php
$connect=mysql_connect("localhost","root","");
$db_selected = mysql_select_db("ong_assessment", $connect);
$query = "SELECT Agent_ID,Address,Bedrooms,Price FROM suburbs";
$result = mysql_query($query) or die(mysql_error());
if(!mysql_affected_rows() >= 1)
{
echo 'There are no entries inside the database';
}

while($row = mysql_fetch_array($result))
{
echo '<tr>';
echo '<td>'. $row['Agent_ID'].'</td>';
echo '<td>'. $row['Address'].'</td>';
echo '<td>'. $row['Bedrooms'].'</td>';
echo '<td>'. $row['Price'].'</td>';
}
echo '</table>';
?>
</body>
</html>

Better? They're no longer constants (:

yes!!! thank you very much. if i got pronlem again you will help me right?

Yes, but, try and solve the problems yourself :)! But, you're welcome to post here and we'll help you.

If this is solved, please mark it as solved and give rep to those who helped!

Good luck

now i need to write report about this php... any suggestion?

Member Avatar for Member #120589

WHat do you mean write a report?

Look at the syntax, if you have to explain what the script does, then it's pretty self-explanatory.. I cannot do your work for you, that wouldn't be fair and I'm sure you actually want to learn something ;) I'll help you a bit though:

  1. Explain what PHP is
  2. Explain the code you've written (So it retrives data from a table inside a database)
  3. Explain each line of code:

    $connect=mysql_connect("localhost","root","");
    $db_selected = mysql_select_db("ong_assessment", $connect);

This code establishes a connection with the database on the server. The mysql_connect accepts three parameters. The mysql_select_db attempts to select the database that data will be retrived from. It accepts two parameters, one is the name of the database and the other is the connection variable.

...

...

...

Something like this :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.