0
<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>
4
Contributors
35
Replies
36
Views
4 Years
Discussion Span
Last Post by phorce
0

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

Edited by phorce

0

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

0

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

Edited by dean.ong.14

0

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?

0

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".

0

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

Edited by dean.ong.14

0

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!

0
<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>
0

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.

0

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

0

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

0
<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 (:

0

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

0

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 :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.