/    Sign up×
Community /Pin to ProfileBookmark

when update data where id=$row[id]

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

this is my code:

[code=php]
$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>”;
}
}
[/code]

Where is the problem?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 15.2015 — Well, as currently written, it's going to update every row fetched by the first query in the code you posted here. If that's not what you want, then I'm guessing maybe you want to use $id (from $_POST['id']) within the update query instead of $rowshow['id'] -- but again, that's just guessing since I don't know what you actually want to happen. If that last guess is correct, then I don't understand why you're looping through the results of the first query, which has me wondering if I'm completely confused?
×

Success!

Help @rooz999 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...