...

View Full Version : Wrong ID when $_Get



ajloun
10-12-2009, 06:50 AM
Hello

i use this code to delete users from mysql tabel , all ok but when click name it deletes wrong user . the last member gets deleted ..dont know why .. but . i use PHP paased in Javascript to call the id . and it does call id but wrong id .

get Rows. for mysql

$result = mysql_query("SELECT * FROM ".$DB->prefix("users")." WHERE level=0 ");
$rows = mysql_num_rows($result);


<script type="text/javascript">
<!--
function confirmation3() {
var answer = confirm("<? echo "are u sure ? "; ?>")
if (answer){

window.location = "user.php?action=st&id=".$row['id']."";
}
else{
alert("<? echo "Canceled"; ?>")
}
}
//-->
</script>

delete link

<a href='#' onclick='confirmation3(); return false;''>delete</a>

do delete


$id = HtmlSpecialchars($_GET['id']);
$query = mysql_query("DELETE FROM ".$DB->prefix("users")." WHERE id='$id'")
or die("cant users");

the thing is if i dont use the href in javascript all work ok just like


<a href=user.php?action=st&id=".$row['id'].">delete</a>

Sergey Popov
10-12-2009, 10:43 AM
Hi. In your function confirmation3() you've messed Javascript code with PHP code. This line need to be fixed:

Your version:


window.location = "user.php?action=st&id=".$row['id']."";


Must be like this:


window.location = "user.php?action=st&id=<?php echo $row['id'] ?>";

ajloun
10-12-2009, 10:24 PM
Hi. In your function confirmation3() you've messed Javascript code with PHP code. This line need to be fixed:

Your version:


window.location = "user.php?action=st&id=".$row['id']."";


Must be like this:


window.location = "user.php?action=st&id=<?php echo $row['id'] ?>";


Thx
But i had it like that
=<?php echo $row['id'] ?>";

and did not work , did not even replace the Vairble to the actual id # so i changed to
=".$row['id']."";
then that worked and that replaced with the ID it just was wrong id ..

IamHe
10-13-2009, 06:54 PM
Thx
But i had it like that
=<?php echo $row['id'] ?>";

and did not work , did not even replace the Vairble to the actual id # so i changed to
=".$row['id']."";
then that worked and that replaced with the ID it just was wrong id ..


Your not defining what user you want to delete.
are you posting the information from another page ? or is there more code from that page?

is this for an admin/mod panel or for the user to delete theyer own acount?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum