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
https://forums.phpfreaks.com/topic/257444-code-check/
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
https://forums.phpfreaks.com/topic/257444-code-check/#findComment-1319484
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
https://forums.phpfreaks.com/topic/257444-code-check/#findComment-1319530
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.