tags:

views:

230

answers:

6

hello,

i have this code.

<?php

$link = mysql_connect('localhost', 'root', 'password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db("ebay");


$query = "SELECT * FROM Auctions";

$result = mysql_query($query) or die(mysql_error());


 $records = array();

 while($row = mysql_fetch_array($result, MYSQL_ASSOC))
 {
      $records[] = $row;
 }

  echo"<table>"

  foreach($records as $row}
  {

  echo"<tr>"
       echo"<td><a href="view_record.php?num="echo $row['Article Number']">echo $row['Article Number']</a></td>"
       echo"<td>echo $row['Article Name']</td>"
   echo"</tr>"
   echo"</table>"


mysql_close($link);

?>

In which I am trying to echo a table, but get this error:

Parse error: syntax error, unexpected T_FOREACH, expecting ',' or ';' in C:\Programme\EasyPHP 2.0b1\www\test.php on line 25

What have I missed?

Also, I know that this is quite a big project, but I am not completely new to programming, as I did java for a good few years, I am just extremely rusty, and having to work on my actual job while trying to do this, so this website is a godsend.

EDIT: Thankyou for your help. I am using Marks repaired version, however I get this error:

Notice: Undefined index: Article Number in test.php on line 29

I plan on studying over the manual when I have some more time, and I didnot give out my real username or password, geheim just means secret in german.

A: 

You just need to put semicolons at the end of all your statments

Dan Walker
+1  A: 

You are missing the ";" at the end of the lines

andy.gurin
+2  A: 

You are missing semi-colon at this line:

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $records[] = $row; }

echo""

should be:

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $records[] = $row; }

echo"";

You are also missing it here:

foreach($records as $row} {

echo"" echo"echo $row['Article Number']" echo"echo $row['Article Name']" echo"" echo""

Should be:

foreach($records as $row} {

echo"" echo"echo $row['Article Number']" echo"echo $row['Article Name']" echo"" echo"";

(And not sure why you have double echo"" there)

kevtrout
A: 

Step one! Don't connect to your DB as root.. and then do not post your root connection information on a public website!

echo"<table>"
  foreach($records as $row}
  {

 echo"<tr>"
 echo"<td><a href="view_record.php?num="echo $row['Article Number']">
 echo $row['Article Number']</a></td>"
 echo"<td>echo $row['Article Name']</td>"
 echo"</tr>"
 echo"</table>"

Should be

echo "<table>";
foreach($records as $row) {
{
  echo "<tr>";
  echo "<td><a href=\"view_record.php?num={$row['Article Number']}\">";
  echo $row['Article Number'] . "</a></td>";
  echo "<td>{$row['Article Name]}</td>";
  echo "</tr>";
  echo "</table>";
}
sobedai
+1  A: 

Edit

As far as the undefined index goes, that just means your database doesn't have a field named Article Number.


It may be worth your while to spend 30 minutes or so working through a PHP tutorial, just to get more comfortable with the syntax.


Here's a fixed version of your foreach loop.

  echo"<table>";

  foreach($records as $row)
  {

       echo "<tr>";
       echo '<td><a href="view_record.php?num=' . $row['Article Number'] . '">' . $row['Article Number'] . '</a></td>';
       echo "<td>" . $row['Article Name'] . "</td>";
       echo "</tr>";
       echo "</table>";
  }
Mark Biek
A: 

When there is "a lot" of HTML involved in output... I like to do this:

foreach($records as $row}
{
?>
    <tr>
        <td><a href="view_record.php?num="<?= $row['Article Number'] ?>">
           <?= $row['Article Number'] ?>
        </a></td>
        <td><?= $row['Article Name'] ?></td>
    </tr>
<?
}

Makes it much easier to read and edit the HTML. Also... might not be a bad idea to make liberal use of htmlentities()...

<?= htmlentities($row['Article Number']) ?>

Just in case.

bobwienholt