Problem in code (Update query)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • praveenkrg
    New Member
    • Sep 2007
    • 17

    #1

    Problem in code (Update query)

    my update query is not working properly!
    [code=php]
    $mgroupname=$_G ET['selectpg'];
    //echo $mgroupname;

    ///query for checking userg_id
    $result=mysql_q uery("SELECT * FROM group WHERE userg_name ='$mgroupname'" );
    while($row = @mysql_fetch_ar ray($result, MYSQL_ASSOC))
    {
    $userg_id=$row['userg_id'];
    $userg_name=$ro w['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_checkbo x=$_POST['modify_checkbo x'];
    $delete_checkbo x=$_POST['delete_checkbo x'];
    $view_checkbox= $_POST['view_checkbox'];

    //$button=$_POST['button'];
    if(strlen($gp_n ame)<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($butt on)<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_checkb ox', deletion = '$delete_checkb ox', viewing = '$view_checkbox ' where userg_id = 2";
    mysql_query($in sertbutton) or die(mysql_error ());
    mysql_query($in sertbutton1) or die(mysql_error ());
    print "Group modify.<BR>";
    print "<a href='main.php' >Go Back</a>";
    }
    }
    else
    {
    print "<form name='form' action='modifyg roup.php' method='post'>" ;
    print "Modify Group Name:<BR>";
    print "<input type='text' name='gp_name' size='20' value='$userg_n ame'><BR><BR>";
    print "Modify Permissions:<BR >";
    print "<input type='checkbox' name='add_check box' value='1'>";
    print "Manage Users&nbsp;<br> ";
    print "<input type='checkbox' name='modify_ch eckbox' value='1'>";
    print "Update/View own info&nbsp;<br>" ;
    print "<input type='checkbox' name='delete_ch eckbox' value='1'>";
    print "Update/View User Salaries/Leave Balance/TDS&nbsp;<br>";
    print "<input type='checkbox' name='view_chec kbox' 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>";
    }
    [/code]
    Last edited by ak1dnar; Jan 7 '08, 01:24 PM. Reason: Fixed code tags
  • rpnew
    New Member
    • Aug 2007
    • 189

    #2
    Originally posted by praveenkrg
    my update query is not working properly!

    $mgroupname=$_G ET['selectpg'];
    //echo $mgroupname;

    ///query for checking userg_id
    $result=mysql_q uery("SELECT * FROM group WHERE userg_name ='$mgroupname'" );
    while($row = @mysql_fetch_ar ray($result, MYSQL_ASSOC))
    {
    $userg_id=$row['userg_id'];
    $userg_name=$ro w['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_checkbo x=$_POST['modify_checkbo x'];
    $delete_checkbo x=$_POST['delete_checkbo x'];
    $view_checkbox= $_POST['view_checkbox'];

    //$button=$_POST['button'];
    if(strlen($gp_n ame)<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($butt on)<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_checkb ox', deletion = '$delete_checkb ox', viewing = '$view_checkbox ' where userg_id = 2";
    mysql_query($in sertbutton) or die(mysql_error ());
    mysql_query($in sertbutton1) or die(mysql_error ());
    print "Group modify.<BR>";
    print "<a href='main.php' >Go Back</a>";
    }
    }
    else
    {
    print "<form name='form' action='modifyg roup.php' method='post'>" ;
    print "Modify Group Name:<BR>";
    print "<input type='text' name='gp_name' size='20' value='$userg_n ame'><BR><BR>";
    print "Modify Permissions:<BR >";
    print "<input type='checkbox' name='add_check box' value='1'>";
    print "Manage Users&nbsp;<br> ";
    print "<input type='checkbox' name='modify_ch eckbox' value='1'>";
    print "Update/View own info&nbsp;<br>" ;
    print "<input type='checkbox' name='delete_ch eckbox' value='1'>";
    print "Update/View User Salaries/Leave Balance/TDS&nbsp;<br>";
    print "<input type='checkbox' name='view_chec kbox' 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

    Comment

    • praveenkrg
      New Member
      • Sep 2007
      • 17

      #3
      Originally posted by rpnew
      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_q uery("SELECT * FROM tez_ems_group WHERE userg_name ='$mgroupname'" );
      while($row = @mysql_fetch_ar ray($result, MYSQL_ASSOC))
      {
      $userg_id=$row['userg_id'];
      $userg_name=$ro w['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_checkb ox', deletion = '$delete_checkb ox', viewing = '$view_checkbox ' where userg_id = '$userg_id'";
      mysql_query($in sertbutton) or die(mysql_error ());
      mysql_query($in sertbutton1) 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?

      Comment

      • rpnew
        New Member
        • Aug 2007
        • 189

        #4
        Originally posted by praveenkrg
        Actually i am not getting any error but this code is not working properly.

        I have fetched the values using this command

        $result=mysql_q uery("SELECT * FROM tez_ems_group WHERE userg_name ='$mgroupname'" );
        while($row = @mysql_fetch_ar ray($result, MYSQL_ASSOC))
        {
        $userg_id=$row['userg_id'];
        $userg_name=$ro w['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_checkb ox', deletion = '$delete_checkb ox', viewing = '$view_checkbox ' where userg_id = '$userg_id'";
        mysql_query($in sertbutton) or die(mysql_error ());
        mysql_query($in sertbutton1) 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

        Comment

        • praveenkrg
          New Member
          • Sep 2007
          • 17

          #5
          Originally posted by rpnew
          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.

          Comment

          • rpnew
            New Member
            • Aug 2007
            • 189

            #6
            Originally posted by praveenkrg
            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

            Comment

            • praveenkrg
              New Member
              • Sep 2007
              • 17

              #7
              Originally posted by rpnew
              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=$_G ET['selectpg'];
              //echo $mgroupname;

              $result=mysql_q uery("SELECT * FROM group WHERE userg_name ='$mgroupname'" );
              while($row = @mysql_fetch_ar ray($result, MYSQL_ASSOC))
              {
              $userg_id=$row['userg_id'];
              $userg_name=$ro w['userg_name'];


              if(isset($_POST['submit']))
              {
              $gp_name=$_POST['gp_name'];
              $add_checkbox=$ _POST['add_checkbox'];
              $modify_checkbo x=$_POST['modify_checkbo x'];
              $delete_checkbo x=$_POST['delete_checkbo x'];
              $view_checkbox= $_POST['view_checkbox'];

              //$button=$_POST['button'];
              if(strlen($gp_n ame)<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_checkb ox', deletion = '$delete_checkb ox', viewing = '$view_checkbox ' where userg_id = '$userg_id'";
              mysql_query($in sertbutton) or die(mysql_error ());
              mysql_query($in sertbutton1) or die(mysql_error ());
              print "Group modify.<BR>";
              print "<a href='main.php' >Go Back</a>";
              }
              }
              else
              {
              print "<form name='form' action='modifyg roup.php' method='post'>" ;
              print "Modify Group Name:<BR>";
              print "<input type='text' name='gp_name' size='20' value='$userg_n ame'><BR><BR>";
              print "Modify Permissions:<BR >";
              print "<input type='checkbox' name='add_check box' value='1'>";
              print "Manage Users&nbsp;<br> ";
              print "<input type='checkbox' name='modify_ch eckbox' value='1'>";
              print "Update/View own info&nbsp;<br>" ;
              print "<input type='checkbox' name='delete_ch eckbox' value='1'>";
              print "Update/View User Salaries/Leave Balance/TDS&nbsp;<br>";
              print "<input type='checkbox' name='view_chec kbox' 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>";
              }
              }

              Comment

              • rpnew
                New Member
                • Aug 2007
                • 189

                #8
                Originally posted by praveenkrg
                Here is my new code:
                $mgroupname=$_G ET['selectpg'];
                //echo $mgroupname;

                $result=mysql_q uery("SELECT * FROM group WHERE userg_name ='$mgroupname'" );
                while($row = @mysql_fetch_ar ray($result, MYSQL_ASSOC))
                {
                $userg_id=$row['userg_id'];
                $userg_name=$ro w['userg_name'];


                if(isset($_POST['submit']))
                {
                $gp_name=$_POST['gp_name'];
                $add_checkbox=$ _POST['add_checkbox'];
                $modify_checkbo x=$_POST['modify_checkbo x'];
                $delete_checkbo x=$_POST['delete_checkbo x'];
                $view_checkbox= $_POST['view_checkbox'];

                //$button=$_POST['button'];
                if(strlen($gp_n ame)<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_checkb ox', deletion = '$delete_checkb ox', viewing = '$view_checkbox ' where userg_id = '$userg_id'";
                mysql_query($in sertbutton) or die(mysql_error ());
                mysql_query($in sertbutton1) or die(mysql_error ());
                print "Group modify.<BR>";
                print "<a href='main.php' >Go Back</a>";
                }
                }
                else
                {
                print "<form name='form' action='modifyg roup.php' method='post'>" ;
                print "Modify Group Name:<BR>";
                print "<input type='text' name='gp_name' size='20' value='$userg_n ame'><BR><BR>";
                print "Modify Permissions:<BR >";
                print "<input type='checkbox' name='add_check box' value='1'>";
                print "Manage Users&nbsp;<br> ";
                print "<input type='checkbox' name='modify_ch eckbox' value='1'>";
                print "Update/View own info&nbsp;<br>" ;
                print "<input type='checkbox' name='delete_ch eckbox' value='1'>";
                print "Update/View User Salaries/Leave Balance/TDS&nbsp;<br>";
                print "<input type='checkbox' name='view_chec kbox' 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

                Comment

                • praveenkrg
                  New Member
                  • Sep 2007
                  • 17

                  #9
                  Originally posted by rpnew
                  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=$_G ET['selectpg'];

                  this variable comes from other page and

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

                  Comment

                  • praveenkrg
                    New Member
                    • Sep 2007
                    • 17

                    #10
                    Originally posted by praveenkrg
                    $mgroupname=$_G ET['selectpg'];

                    this variable comes from other page and

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

                    Hi RP,

                    could you tell me whts the error in this query:

                    $result = mysql_query("up date 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 ());

                    Comment

                    • Markus
                      Recognized Expert Expert
                      • Jun 2007
                      • 6092

                      #11
                      Originally posted by praveenkrg
                      Hi RP,

                      could you tell me whts the error in this query:

                      $result = mysql_query("up date 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.

                      Comment

                      • praveenkrg
                        New Member
                        • Sep 2007
                        • 17

                        #12
                        Originally posted by markusn00b
                        Do you get an error?

                        Post the rest of the code if not.
                        I have solved my problem. Thanks for all help and support :)

                        Comment

                        • rpnew
                          New Member
                          • Aug 2007
                          • 189

                          #13
                          Originally posted by praveenkrg
                          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

                          Comment

                          Working...