0

I am trying to update the field id_key which is an unique value using uniqid() function. When I print to the screen the value for uniqid() [$id] is different for each record. Which is correct and is what I want.

However when I go inspect the table all the values in the id_key column are the same for each record. What am I doing wrong? Each record should have a different value - the value shown on the screen with my echo statement.

while ($row = mysql_fetch_array($loop))
{
    $id = uniqid();
    echo $row['rec'] . " " . $row['first_name'] . " " . $row['email'] . " "  . $id . "<br/>";
    $query="UPDATE va SET id_key='$id'";
    mysql_query($query) or die ("Error in query: $query <br>" . error_message);
}   
3
Contributors
3
Replies
14
Views
3 Years
Discussion Span
Last Post by Mike_H
0

You are missing the WHERE clause in the query

$query="UPDATE va SET id_key='$id' WHERE id_key='".$row['id_key']."'";
0

If type of id_key is INTEGER then try set value without apostrophes

$query="UPDATE va SET id_key=$id";

or

$query="UPDATE va SET id_key=".$id;
0

niranga,
You fixed it for me, all that was needed was the where clause. I did not realize that I would need one here but now I know.
Thanks!

AndrisP,
Your suggestion would give me an error in the query message. The values looks like this: 540f17638b808
The field type is varchar(13).
Thanks for your help. I will keep it in mind when I have a similar situation.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.