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

?>
4
  • Do people learn to read or not? Mysql_* function so bad.... Commented Sep 13, 2012 at 12:05
  • as far as I can see, you are selecting an ID field, and using uid on the rows Commented Sep 13, 2012 at 12:05
  • wow, check all the reactions... the problem is obvius Commented Sep 13, 2012 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 stackoverflow.com/questions/548986/mysql-vs-mysqli-in-php. If you're not using those, then you shouldn't encounter any issues... Commented Sep 13, 2012 at 14:03

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

It's even better if he uses PDO instead of mysqli.
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 ;)
2

shouldnt it be:

$row['ID'] 

instead of

$row['uid'] 

Comments

1

You echo

$row['uid']

But your Selecting from de database:

$row['ID']

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.