Jump to content

Code Check


raggy99

Recommended Posts

I have been getting errors with the code below.

Can someone please tell me where I went Wrong.

 

<?php
define('DB_NAME', 'raggsweb_oltusers');
define('DB_USER', 'raggsweb_raggs');
define('DB_PASSWORD', 'XXXXXXX');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('çould not connect: '. mysql_error());
}
mysql_select_db(DB_NAME, $link);

$result = mysql_query ('SELECT * FROM Users') or die ('Error: '.mysql_error ());

echo "<table>
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>Title</td>
<td>Location</td>
<td>Office Phone</td>
<td>Office Extention</td>
<td>Mobile</td>
<td>Edit</td>
<td> </td>
</tr>
</table>"

while($row = mysql_fetch_array($result));
{
echo '<tr>';
echo '<td>'.$row['Firstname'].'</td>';
echo '<td>'.$row['Lastname'].'</td>';
echo '<td>'.$row['Title'].'</td>';
echo '<td>'.$row['Location'].'</td>';
echo '<td>'.$row['Officephone'].'</td>';
echo '<td>'.$row['Officeextention'].'</td>';
echo '<td>'.$row['Mobile'].'</td>';
echo '<td>'.$row['Email'].'</td>';
echo '<td>' '</td>';
echo '</tr>';
}
mysql_close();
?>

 

Thanks In Advance

Link to comment
Share on other sites

Hey There,

I don't know if it matters with your database connect setup

<?php

define('DB_NAME', 'raggsweb_oltusers');

define('DB_USER', 'raggsweb_raggs');

define('DB_PASSWORD', 'XXXXXXX');

define('DB_HOST', 'localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

should be

 

<?php

define('DB_HOST', 'localhost'_;

define('DB_USER', 'raggsweb_raggs');

define('DB_PASSWORD', 'XXXXXXX');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

 

(It may be that your not corresponding in order)

 

or

 

$result = mysql_query ('SELECT * FROM Users') or die ('Error: '.mysql_error ());

 

possibly

 

$query = mysql_query("select * FROM Users WHERE username = '$user'"); // Queries the Database to check if the user already exsists

 

Change the values that are different to the values from your database

 

 

Let me know if this wasn't the problem...

 

This is all I could see may be wrong

Link to comment
Share on other sites

You're missing a semicolon after displaying the table header:

 

<?php
//...

echo "<table>
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>Title</td>
<td>Location</td>
<td>Office Phone</td>
<td>Office Extention</td>
<td>Mobile</td>
<td>Edit</td>
<td> </td>
</tr>
</table>"   //<--- ADD SEMICOLON HERE

//...
?>

 

 

The while loop shouldn't have a semicolon after it:

 

<?php
//...

while($row = mysql_fetch_array($result));  //<--- REMOVE SEMICOLON
{

//...
?>

 

 

Also, as Andy-H stated, the close tag for the table should go after all the table rows.

 

<?php
//...

echo "<table>
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>Title</td>
<td>Location</td>
<td>Office Phone</td>
<td>Office Extention</td>
<td>Mobile</td>
<td>Edit</td>
<td> </td>
</tr>";

while($row = mysql_fetch_array($result))
{
     echo '<tr>';
     //...
     echo '</tr>';
}
echo '</table>';

//...
?>

 

 

For bonus points, you should also utilize the table heading tag and scope attribute.

 

<?php
//...

echo "<table>
<tr>
<th scope='col'>First Name</th>
<th scope='col'>Last Name</th>
<th scope='col'>Title</th>
<th scope='col'>Location</th>
<th scope='col'>Office Phone</th>
<th scope='col'>Office Extention</th>
<th scope='col'>Mobile</th>
<th scope='col'>Edit</th>
<th scope='col'> </th>
</tr>";

//...
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.