Jump to content

when update data where id=$row[id]


rooz999

Recommended Posts

I want to update data row But the problem is that it is updated All rows

this is my code:

$query = mysql_query("SELECT * 
                      FROM emp 
                          JOIN inv ON emp.name=inv.empname 
                      WHERE inv.empname='".$name."'") 
                or die ("mysql error query");

$id = $_POST['id'];
$updatestartdate = date('d/m/Y');
$updateenddate = date('d/m/Y');
$status = $_POST['status'];

while ($rowshow = mysql_fetch_assoc($query)){
    $timetoshow = unix_time($rowshow['timex']);

    //UPDATE
    if (isset($_POST['Update']) and $_POST['Update'] == 'dataupdate'){

        $updatestatus = mysql_query ("UPDATE inv SET 
                                     updatestartdate='$updatestartdate',
                                     updateenddate='$updateenddate',
                                     status='$status' 
                                     WHERE id='".$rowshow['id']."'")
                        or die ("updatestatus Error");

        if (isset ($updatestatus)){
            echo "<div class='hidecontent'><h3 style='background-color:#3F3F3F; padding:5px;' align='center'>
                <font color='#FFFFFF'>Update is done</font></h3><meta http-equiv='Refresh' content='5; url=cpanel_user.php' /></div>";
        } else  {
            echo "<div class='hidecontent'><h3 style='background-color:#FF0000; padding:5px;' align='center'>
<font color='#FFFF00'>Update Error</font></h3></div>";
        }
    }

Where is the problem?

Link to comment
Share on other sites

Note that you could also consider running the query outside of the loop. Instead of using $rowshow, you probably could just use the GET variable that was assigned to $id.

$updatestatus = mysql_query ("UPDATE inv SET 
                                     updatestartdate='$updatestartdate',
                                     updateenddate='$updateenddate',
                                     status='$status' 
                                     WHERE id='".$id."'")
                        or die ("updatestatus Error");

Of course, you would want to verify that $id contains an expected value to avoid SQL injection attacks.

Edited by cyberRobot
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.