how to access the ID?
In the website I'm designing the admin list page shows fields such as Name, Email, Username and St开发者_JAVA百科atus(whether active or inactive users). My database has a table called admin. The fields are iAdminId, vFirstName, vLastName, vEmail, vUserName, vPassword, vFromIP, vFromIP, dLastLogin, and eStatus. In the equivalent PHP page (the admin list page) I am adding an active & inactive button. Check boxes are present with each row. The number of rows that an administrator chooses will be updated(after confirmation, of course) once he/she clicks on Active or Inactive button.
My javscript code for activation is:
function activeRecord()
{
var count = getCount();
if(count == 0)
{
alert("Please enter some records for activation first!!");
}
else
{
var c = confirm("Do you wish to activate?");
if(c==true)
{
document.frm.mode.value="Active";
document.frm.submit();
}
else
{
alert("You had wrongly selected 'Active' option!!");
}
}
}
getCount returns the number of selected records. And PHP code is
if($mode=="Active")
{
for($i=0;$i<count($_POST['ch']);$i++)
{
$active = "UPDATE admin SET eStatus = 'Active' WHERE iAdminId = '" . $_POST['ch'][$i] . "'";
$result = mysql_query($active,$conn);
}
}
Even after selecting its not deleting the selected records. I tried echoing also.
echo $active = "UPDATE admin SET eStatus = 'Active' WHERE iAdminId = '" . $_POST['ch'][$i] . "'";
"ch" is the array name for all the checkboxes
It shows: UPDATE admin SET eStatus = 'Inactive' WHERE iAdminId = ''
Any help will be appreciated. Thanks in advance
ch is used as:
Pls help. Its urgent. Thanks everybody
In your case $_POST['ch']
should be an array. Check if that's true by placing var_dump($_POST['ch'])
in your PHP script.
Also your checkboxes should use the same name (<input name="ch[]" value="Element-ID" />
).
There's no need in adding an index in the brackets. If you do so, your for-Loop (which could be replaced by foreach
) won't work since you're just checking the length and iterate through the array with the wrong keys.
Sorry for bothering everybody and loads of thanks for paying the interest in solving my problem.
I guess i needed an extra pair of eyes for checking my code. As @fabsn asked i rechecked my code. I had entered value for the check boxes. So there was no chance of them going blank. It was all just a minor spelling mistake. Its corrected now and working absolutely fine now. I guess i need to be more careful from now onwards so that i dont bother you all unnecessarily.
Thanks again
精彩评论