473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem in code (Update query)

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
12 1845
rpnew
188 100+
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
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
188 100+
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
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
188 100+
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
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
188 100+
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
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
$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
6,050 Expert 4TB
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
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
188 100+
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

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

Similar topics

3
by: Kulnor | last post by:
My hosting company upgraded yesterday to pHp 4.3.10. Since then, all my INSERT/UPDATE/DELET query on our MS-SQL database seem to fail. No specific error message is returned by...
0
by: hiisikukko | last post by:
I have created project management software with Java and MySql and i works fine. This applet gets and writes information directly to MySql database. Problem is that those sqlClauses below(update...
3
by: rrh | last post by:
I am trying to update a field in one table with data from another table. The problem I'm running into is I need to base the update on a range of data in the 2nd table. Table 1 has: date field...
31
by: Lag | last post by:
Having a problem updating my database from a web page, through a submission form. Can anyone help? ----THIS IS MY CODE IN update.php----(user, pass, and database are typed in directly, I...
3
by: Juan Antonio Villa | last post by:
Hello, I'm having a problem replicating a simple database using the binary log replication, here is the problem: When the master sends an update to the slave, an example update reads as follows:...
15
by: sara | last post by:
I have a Memo field in a table to hold notes from a conversation a social worker has had with a client (this is for a non-profit). If the user needs to update the memo field, I need to find the...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
4
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
4
by: pankajsingh5k | last post by:
Hi guys, These question is for all the experts... Please help me before my brain explodes The problem is again with the formview control.. I have a formview and i have to use it that...
1
by: giovannino | last post by:
Dear all, I did a query which update a sequence number (column NR_SEQUENZA) in a table using a nice code (from Trevor !). 1) Given that I'm not a programmer I can't understand why...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.