By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,401 Members | 814 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,401 IT Pros & Developers. It's quick & easy.

Problem in code (Update query)

P: 17
my update query is not working properly!
Expand|Select|Wrap|Line Numbers
  1. $mgroupname=$_GET['selectpg'];
  2. //echo $mgroupname;
  3.  
  4. ///query for checking userg_id
  5. $result=mysql_query("SELECT * FROM group WHERE userg_name ='$mgroupname'");
  6. while($row = @mysql_fetch_array($result, MYSQL_ASSOC))
  7. {  
  8. $userg_id=$row['userg_id'];
  9. $userg_name=$row['userg_name'];
  10.  
  11. //echo $userg_id;
  12. //echo $userg_name;
  13. ///query for checking userg_id
  14. }  
  15.  
  16. if(isset($_POST['submit']))
  17. {
  18.   $gp_name=$_POST['gp_name'];
  19.   $add_checkbox=$_POST['add_checkbox'];
  20.   $modify_checkbox=$_POST['modify_checkbox'];
  21.   $delete_checkbox=$_POST['delete_checkbox'];
  22.   $view_checkbox=$_POST['view_checkbox'];
  23.  
  24.   //$button=$_POST['button'];
  25.   if(strlen($gp_name)<1)
  26.   {
  27.       print "You did not enter a Group Name.<BR>";
  28.       print "<a href='addgroup.php'>Go Back</a> &amp; Enter a Group Name.";
  29.   }
  30.   //else if(strlen($button)<1)
  31.   //{
  32.       //print "You did not enter a button.";
  33.   //}
  34.   else
  35.   {
  36.     $insertbutton="update group SET userg_name = '$gp_name' where userg_id = 2 ";
  37.     $insertbutton1="update rights SET addition = '$add_checkbox', editing = '$modify_checkbox', deletion = '$delete_checkbox', viewing = '$view_checkbox' where userg_id = 2";
  38.     mysql_query($insertbutton) or die(mysql_error());
  39.     mysql_query($insertbutton1) or die(mysql_error());
  40.     print "Group modify.<BR>";
  41.     print "<a href='main.php'>Go Back</a>";
  42.   }
  43. }
  44. else
  45. {
  46.     print "<form name='form' action='modifygroup.php' method='post'>";
  47.     print "Modify Group Name:<BR>";
  48.     print "<input type='text' name='gp_name' size='20' value='$userg_name'><BR><BR>";
  49.     print "Modify Permissions:<BR>";
  50.     print "<input type='checkbox' name='add_checkbox' value='1'>";
  51.     print "Manage Users&nbsp;<br>";
  52.     print "<input type='checkbox' name='modify_checkbox' value='1'>";
  53.     print "Update/View own info&nbsp;<br>";
  54.     print "<input type='checkbox' name='delete_checkbox' value='1'>";
  55.     print "Update/View User Salaries/Leave Balance/TDS&nbsp;<br>";
  56.     print "<input type='checkbox' name='view_checkbox' value='1'>";
  57.     print "Update/View User attendance&nbsp;<br><BR><BR>";
  58.     print "<input type='submit' name='submit' value='Update'></form><BR>";
  59.     print "<a href='main.php'>Go Back</a>";
  60. }
  61.  
Jan 7 '08 #1
Share this Question
Share on Google+
12 Replies


rpnew
100+
P: 188
my update query is not working properly!

$mgroupname=$_GET['selectpg'];
//echo $mgroupname;

///query for checking userg_id
$result=mysql_query("SELECT * FROM group WHERE userg_name ='$mgroupname'");
while($row = @mysql_fetch_array($result, MYSQL_ASSOC))
{
$userg_id=$row['userg_id'];
$userg_name=$row['userg_name'];

//echo $userg_id;
//echo $userg_name;
///query for checking userg_id
}

if(isset($_POST['submit']))
{
$gp_name=$_POST['gp_name'];
$add_checkbox=$_POST['add_checkbox'];
$modify_checkbox=$_POST['modify_checkbox'];
$delete_checkbox=$_POST['delete_checkbox'];
$view_checkbox=$_POST['view_checkbox'];

//$button=$_POST['button'];
if(strlen($gp_name)<1)
{
print "You did not enter a Group Name.<BR>";
print "<a href='addgroup.php'>Go Back</a> &amp; Enter a Group Name.";
}
//else if(strlen($button)<1)
//{
//print "You did not enter a button.";
//}
else
{
$insertbutton="update group SET userg_name = '$gp_name' where userg_id = 2 ";
$insertbutton1="update rights SET addition = '$add_checkbox', editing = '$modify_checkbox', deletion = '$delete_checkbox', viewing = '$view_checkbox' where userg_id = 2";
mysql_query($insertbutton) or die(mysql_error());
mysql_query($insertbutton1) or die(mysql_error());
print "Group modify.<BR>";
print "<a href='main.php'>Go Back</a>";
}
}
else
{
print "<form name='form' action='modifygroup.php' method='post'>";
print "Modify Group Name:<BR>";
print "<input type='text' name='gp_name' size='20' value='$userg_name'><BR><BR>";
print "Modify Permissions:<BR>";
print "<input type='checkbox' name='add_checkbox' value='1'>";
print "Manage Users&nbsp;<br>";
print "<input type='checkbox' name='modify_checkbox' value='1'>";
print "Update/View own info&nbsp;<br>";
print "<input type='checkbox' name='delete_checkbox' value='1'>";
print "Update/View User Salaries/Leave Balance/TDS&nbsp;<br>";
print "<input type='checkbox' name='view_checkbox' value='1'>";
print "Update/View User attendance&nbsp;<br><BR><BR>";
print "<input type='submit' name='submit' value='Update'></form><BR>";
print "<a href='main.php'>Go Back</a>";
}
Hi,
What is the problem or error you're getting?

Regards,
RP
Jan 7 '08 #2

P: 17
Hi,
What is the problem or error you're getting?

Regards,
RP
Actually i am not getting any error but this code is not working properly.

I have fetched the values using this command

$result=mysql_query("SELECT * FROM tez_ems_group WHERE userg_name ='$mgroupname'");
while($row = @mysql_fetch_array($result, MYSQL_ASSOC))
{
$userg_id=$row['userg_id'];
$userg_name=$row['userg_name'];

echo $userg_id;
echo $userg_name;
}

till here it runs fine but after this i have a submit button. some where in the middle of the code

i have written this

else
{
$insertbutton="update tez_ems_group SET userg_name = '$gp_name' where userg_id = '$userg_id' ";
$insertbutton1="update tez_ems_rights SET addition = '$add_checkbox', editing = '$modify_checkbox', deletion = '$delete_checkbox', viewing = '$view_checkbox' where userg_id = '$userg_id'";
mysql_query($insertbutton) or die(mysql_error());
mysql_query($insertbutton1) or die(mysql_error());


Before the submit button $userg_id prints the values but in this line

$insertbutton="update tez_ems_group SET userg_name = '$gp_name' where userg_id = '$userg_id' ";

it doesn't print the value. why?
Jan 7 '08 #3

rpnew
100+
P: 188
Actually i am not getting any error but this code is not working properly.

I have fetched the values using this command

$result=mysql_query("SELECT * FROM tez_ems_group WHERE userg_name ='$mgroupname'");
while($row = @mysql_fetch_array($result, MYSQL_ASSOC))
{
$userg_id=$row['userg_id'];
$userg_name=$row['userg_name'];

echo $userg_id;
echo $userg_name;
}

till here it runs fine but after this i have a submit button. some where in the middle of the code

i have written this

else
{
$insertbutton="update tez_ems_group SET userg_name = '$gp_name' where userg_id = '$userg_id' ";
$insertbutton1="update tez_ems_rights SET addition = '$add_checkbox', editing = '$modify_checkbox', deletion = '$delete_checkbox', viewing = '$view_checkbox' where userg_id = '$userg_id'";
mysql_query($insertbutton) or die(mysql_error());
mysql_query($insertbutton1) or die(mysql_error());


Before the submit button $userg_id prints the values but in this line

$insertbutton="update tez_ems_group SET userg_name = '$gp_name' where userg_id = '$userg_id' ";

it doesn't print the value. why?
Hi,
I'm not sure about this but... you have this problem.... that you are fetching values using 'WHILE' loop and you are not getting it outside the 'WHILE' loop and thats what happens as per my PHP knowledge. If you want to be sure for this try 'echoing' your value outside the while loop. so if you want to do anything with those value. Put all those code in the while loop(and from your first post. i think you need to put your IF-ELSE into while. But be aware it will run as many times as that while loop runs so change accordingly if needed or get back here again)
Thats my solution. Try that or let someone come with better solution..

Regards,
RP
Jan 8 '08 #4

P: 17
Hi,
I'm not sure about this but... you have this problem.... that you are fetching values using 'WHILE' loop and you are not getting it outside the 'WHILE' loop and thats what happens as per my PHP knowledge. If you want to be sure for this try 'echoing' your value outside the while loop. so if you want to do anything with those value. Put all those code in the while loop(and from your first post. i think you need to put your IF-ELSE into while. But be aware it will run as many times as that while loop runs so change accordingly if needed or get back here again)
Thats my solution. Try that or let someone come with better solution..

Regards,
RP
Hi,
when i put my IF-ELSE part in WHILE loop then it display nothing.
Jan 8 '08 #5

rpnew
100+
P: 188
Hi,
when i put my IF-ELSE part in WHILE loop then it display nothing.
Hi,
Can you post your new code here??
And one more thing i would like you to check is make sure that all your loops and conditions are working accordingly...
Regards,
RP
Jan 8 '08 #6

P: 17
Hi,
Can you post your new code here??
And one more thing i would like you to check is make sure that all your loops and conditions are working accordingly...
Regards,
RP
Here is my new code:
$mgroupname=$_GET['selectpg'];
//echo $mgroupname;

$result=mysql_query("SELECT * FROM group WHERE userg_name ='$mgroupname'");
while($row = @mysql_fetch_array($result, MYSQL_ASSOC))
{
$userg_id=$row['userg_id'];
$userg_name=$row['userg_name'];


if(isset($_POST['submit']))
{
$gp_name=$_POST['gp_name'];
$add_checkbox=$_POST['add_checkbox'];
$modify_checkbox=$_POST['modify_checkbox'];
$delete_checkbox=$_POST['delete_checkbox'];
$view_checkbox=$_POST['view_checkbox'];

//$button=$_POST['button'];
if(strlen($gp_name)<1)
{
print "You did not enter a Group Name.<BR>";
print "<a href='addgroup.php'>Go Back</a> &amp; Enter a Group Name.";
}
else
{
$insertbutton="update group SET userg_name = '$gp_name' where userg_id = '$userg_id' ";
$insertbutton1="update tez_ems_rights SET addition = '$add_checkbox', editing = '$modify_checkbox', deletion = '$delete_checkbox', viewing = '$view_checkbox' where userg_id = '$userg_id'";
mysql_query($insertbutton) or die(mysql_error());
mysql_query($insertbutton1) or die(mysql_error());
print "Group modify.<BR>";
print "<a href='main.php'>Go Back</a>";
}
}
else
{
print "<form name='form' action='modifygroup.php' method='post'>";
print "Modify Group Name:<BR>";
print "<input type='text' name='gp_name' size='20' value='$userg_name'><BR><BR>";
print "Modify Permissions:<BR>";
print "<input type='checkbox' name='add_checkbox' value='1'>";
print "Manage Users&nbsp;<br>";
print "<input type='checkbox' name='modify_checkbox' value='1'>";
print "Update/View own info&nbsp;<br>";
print "<input type='checkbox' name='delete_checkbox' value='1'>";
print "Update/View User Salaries/Leave Balance/TDS&nbsp;<br>";
print "<input type='checkbox' name='view_checkbox' value='1'>";
print "Update/View User attendance&nbsp;<br><BR><BR>";
print "<input type='submit' name='submit' value='Update'></form><BR>";
print "<a href='main.php'>Go Back</a>";
}
}
Jan 8 '08 #7

rpnew
100+
P: 188
Here is my new code:
$mgroupname=$_GET['selectpg'];
//echo $mgroupname;

$result=mysql_query("SELECT * FROM group WHERE userg_name ='$mgroupname'");
while($row = @mysql_fetch_array($result, MYSQL_ASSOC))
{
$userg_id=$row['userg_id'];
$userg_name=$row['userg_name'];


if(isset($_POST['submit']))
{
$gp_name=$_POST['gp_name'];
$add_checkbox=$_POST['add_checkbox'];
$modify_checkbox=$_POST['modify_checkbox'];
$delete_checkbox=$_POST['delete_checkbox'];
$view_checkbox=$_POST['view_checkbox'];

//$button=$_POST['button'];
if(strlen($gp_name)<1)
{
print "You did not enter a Group Name.<BR>";
print "<a href='addgroup.php'>Go Back</a> &amp; Enter a Group Name.";
}
else
{
$insertbutton="update group SET userg_name = '$gp_name' where userg_id = '$userg_id' ";
$insertbutton1="update tez_ems_rights SET addition = '$add_checkbox', editing = '$modify_checkbox', deletion = '$delete_checkbox', viewing = '$view_checkbox' where userg_id = '$userg_id'";
mysql_query($insertbutton) or die(mysql_error());
mysql_query($insertbutton1) or die(mysql_error());
print "Group modify.<BR>";
print "<a href='main.php'>Go Back</a>";
}
}
else
{
print "<form name='form' action='modifygroup.php' method='post'>";
print "Modify Group Name:<BR>";
print "<input type='text' name='gp_name' size='20' value='$userg_name'><BR><BR>";
print "Modify Permissions:<BR>";
print "<input type='checkbox' name='add_checkbox' value='1'>";
print "Manage Users&nbsp;<br>";
print "<input type='checkbox' name='modify_checkbox' value='1'>";
print "Update/View own info&nbsp;<br>";
print "<input type='checkbox' name='delete_checkbox' value='1'>";
print "Update/View User Salaries/Leave Balance/TDS&nbsp;<br>";
print "<input type='checkbox' name='view_checkbox' value='1'>";
print "Update/View User attendance&nbsp;<br><BR><BR>";
print "<input type='submit' name='submit' value='Update'></form><BR>";
print "<a href='main.php'>Go Back</a>";
}
}
Hi,
Let me know one more thin....... you are using $_GET somewhere and somewhere $_POST.. why so?? arent they coming from the same page??

P.S.: Going through your code meanwhile.
Regards,
RP
Jan 8 '08 #8

P: 17
Hi,
Let me know one more thin....... you are using $_GET somewhere and somewhere $_POST.. why so?? arent they coming from the same page??

P.S.: Going through your code meanwhile.
Regards,
RP
$mgroupname=$_GET['selectpg'];

this variable comes from other page and

if(isset($_POST['submit']))
{
$gp_name=$_POST['gp_name'];
$add_checkbox=$_POST['add_checkbox'];
$modify_checkbox=$_POST['modify_checkbox'];
.........
this one is from same page.
Jan 8 '08 #9

P: 17
$mgroupname=$_GET['selectpg'];

this variable comes from other page and

if(isset($_POST['submit']))
{
$gp_name=$_POST['gp_name'];
$add_checkbox=$_POST['add_checkbox'];
$modify_checkbox=$_POST['modify_checkbox'];
.........
this one is from same page.

Hi RP,

could you tell me whts the error in this query:

$result = mysql_query("update tez_ems_users SET user_name = '$gp_name', user_password = '$c_pass', first_name = '$f_name', last_name = '$l_name', email = '$email', emp_number = '$emp_number', userg_id = '$selectpg' where user_name = '$gp_name'") or die(mysql_error());
Jan 8 '08 #10

Markus
Expert 5K+
P: 6,050
Hi RP,

could you tell me whts the error in this query:

$result = mysql_query("update tez_ems_users SET user_name = '$gp_name', user_password = '$c_pass', first_name = '$f_name', last_name = '$l_name', email = '$email', emp_number = '$emp_number', userg_id = '$selectpg' where user_name = '$gp_name'") or die(mysql_error());
Do you get an error?

Post the rest of the code if not.
Jan 8 '08 #11

P: 17
Do you get an error?

Post the rest of the code if not.
I have solved my problem. Thanks for all help and support :)
Jan 9 '08 #12

rpnew
100+
P: 188
I have solved my problem. Thanks for all help and support :)
Hi,
Nice to hear that you've solved your problem...

What was your problem? and how did you solve it?

Regards,
RP
Jan 9 '08 #13

Post your reply

Sign in to post your reply or Sign up for a free account.