0

I am at scripting a customer database. When I wanted to implement the "manage customers" site where you can edit, delete and view details of each entry, I encountered a strange problem. Everything works like expected, but the ID field is left empty and added nowhere.

I have the following code:

    <?php
$qresult = mysql_query("SELECT ID , FirstName, LastName, Company FROM hs_customers");

echo "<table class='coverview' border='0' width='100%' cellpadding='0' cellspacing='0'>";
echo "<th>FirstName</th>
      <th>LastName</th>
      <th>Company</th>
      <th>Options</th>";

while($row = mysql_fetch_array($qresult))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>" . 
     "<td>" . $row['LastName'] . "</td>" . 
     "<td>" . $row['Company'] . "</td>" . 
     "<td>" . "<a href='?action=details&id='" . $row['ID'] . "'>Details</a>" .     " " . 
     "<a href='?action=edit&id='" . $row['ID'] . "'>Edit</a>" . " " . 
     "<a href='?action=delete&id='" . $row['ID'] . "'>Delete</a>" . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);

?>
Florent
  • 12,310
  • 10
  • 49
  • 58
Dreshar
  • 117
  • 11
  • Do people learn to read or not? Mysql_* function so bad.... – Ron van der Heijden Sep 13 '12 at 12:05
  • as far as I can see, you are selecting an ID field, and using uid on the rows – guiligan Sep 13 '12 at 12:05
  • wow, check all the reactions... the problem is obvius – Mathlight Sep 13 '12 at 12:06
  • Why do people say its, "so bad." It's still in use today on older systems and is still functional. I have a project I built years ago that uses mysql functions and performs very well to this day. As shown on this post, the main advantage of mysqli vs mysql is that it uses prepared statements http://stackoverflow.com/questions/548986/mysql-vs-mysqli-in-php. If you're not using those, then you shouldn't encounter any issues... – user1477388 Sep 13 '12 at 14:03

4 Answers4

5

You use $row['uid'] but you select ID from your query, so should be row['ID']

Moreover, don't use anymore function like mysql_query. As you can read here is discouraged. Please use msqli instead.

The best solution is to use PDO. Please take a look to them too.

DonCallisto
  • 29,419
  • 9
  • 72
  • 100
  • It's even better if he uses `PDO` instead of `mysqli`. – tftd Sep 13 '12 at 12:09
  • Thank you for your replies. @DonCallisto - i was using ID too i forgot to edit it back while posting it here - still same result. I didn't knew that this is obsolete. Thank you for the tip ;) – Dreshar Sep 13 '12 at 13:55
2

shouldnt it be:

$row['ID'] 

instead of

$row['uid'] 
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
1

You echo

$row['uid']

But your Selecting from de database:

$row['ID']
Mathlight
  • 6,436
  • 17
  • 62
  • 107
1

Well I guess it's just because you use $row['uid'] but in your SQL query you're using ID. You should be using $row['ID'] instead.

newfurniturey
  • 37,556
  • 9
  • 94
  • 102
RemyG
  • 486
  • 5
  • 11