PHP code: No error message but not working.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #16
    Originally posted by proudlyphp
    If I get you right, I have the PhpMyAdmin panel where by I created the database and I changed the privilege to ALL in this panel, still the problem is the same.

    That is why I tried the code.

    Shall I just use your comment as

    $grt = "GRANT ALL TO *.* TO 'swhisa_canserv er'@'%'
    mysql_query($gr t) or die....

    in the same php file.
    Please do something.
    That probably won't work. If swhisa_canserve r can't insert then they most likely don't have GRANT priviledges as well.
    You have to do it as someone with GRANT priviledges. You need to do the equivalent of that statement in phpmyadmin or just run it after connecting to mysql from a command prompt.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #17
      The GRANT query should be run by an administrative account only once to give your user the ability to use the INSERT command.
      Planting it at a random location in your PHP code will do nothing but cause more errors.

      Try using your phpMyAdmin program to run that query. I'm not familliar with how exactly that app works, but I'm sure it has the ability to run custom queries.

      One a different note... Why do you add \' surrounding the value of the INSERT query? It will probably just add single-quote marks around the value inside the database.

      Comment

      • proudlyphp
        New Member
        • Jul 2008
        • 16

        #18
        Originally posted by Atli
        The GRANT query should be run by an administrative account only once to give your user the ability to use the INSERT command.
        Planting it at a random location in your PHP code will do nothing but cause more errors.

        Try using your phpMyAdmin program to run that query. I'm not familliar with how exactly that app works, but I'm sure it has the ability to run custom queries.

        One a different note... Why do you add \' surrounding the value of the INSERT query? It will probably just add single-quote marks around the value inside the database.
        Dear All,
        I have tried to simplify everything from scratch. I have embedded the GRANT query string after I am connected to the MySQL database as


        [code=php]
        <?php
        define('MYSQL_H OST','localhost ');
        define('MYSQL_U SER','swhisa_sw hisa');
        define('MYSQL_P ASS','alex123') ;
        define('MYSQL_D B','swhisa_swhi sadb');
        if(!mysql_conne ct (MYSQL_HOST, MYSQL_USER, MYSQL_PASS)){di e (mysql_error()) ; } mysql_select_db (MYSQL_DB);

        $grt = "GRANT ALL TO *.* TO 'swhisa_swhisa' @'%'";
        mysql_query($gr t) or die(mysql_error ());

        ?>


        [/code]

        this code is giving me the following error message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TO *.* TO 'swhisa_swhisa' @'%'' at line 1

        Now it seems that I might be able to grant privileges with some comment on the code above.

        I need your help
        Last edited by Atli; Jul 29 '08, 03:13 PM. Reason: Fixed [code] tags

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #19
          Originally posted by proudlyphp
          Dear All,
          I have tried to simplify everything from scratch. I have embedded the GRANT query string after I am connected to the MySQL database as


          [code=php]
          <?php
          define('MYSQL_H OST','localhost ');
          define('MYSQL_U SER','swhisa_sw hisa');
          define('MYSQL_P ASS','alex123') ;
          define('MYSQL_D B','swhisa_swhi sadb');
          if(!mysql_conne ct (MYSQL_HOST, MYSQL_USER, MYSQL_PASS)){di e (mysql_error()) ; } mysql_select_db (MYSQL_DB);

          $grt = "GRANT ALL TO *.* TO 'swhisa_swhisa' @'%'";
          mysql_query($gr t) or die(mysql_error ());

          ?>


          [code]

          this code is giving me the following error message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TO *.* TO 'swhisa_swhisa' @'%'' at line 1

          Now it seems that I might be able to grant privileges with some comment on the code above.

          I need your help
          Read the last two responses again. The key thing is the user who is performing the GRANT command. That user needs to have administrative priviledges. More specifically they need to have GRANT priviledges. If they don't have insert priviledges then most likely they don't have GRANT priviledges as well.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #20
            Please do not double post. I've deleted the thread you just created for this same problem.

            Comment

            • proudlyphp
              New Member
              • Jul 2008
              • 16

              #21
              Originally posted by r035198x
              Read the last two responses again. The key thing is the user who is performing the GRANT command. That user needs to have administrative priviledges. More specifically they need to have GRANT priviledges. If they don't have insert priviledges then most likely they don't have GRANT priviledges as well.
              I have the privilege. The following is what I copied from PhpMyAdmin panel for you to see. I went to the PhpMyAdmin and gave an ALL grant.

              Users in swhisadb
              swhisa_swhisa (Privileges: ALL PRIVILEGES)

              And again I wrote the code inside the connecttodb.php just after connecting, as you recommended. I will show you the improved code and the new error message I got as below:

              The following is the improved connection string.

              [code=php]
              <?php
              define('MYSQL_H OST','localhost ');
              define('MYSQL_U SER','swhisa_sw hisa');
              define('MYSQL_P ASS','#nd3R');
              define('MYSQL_D B','swhisa_swhi sadb');
              if(!mysql_conne ct (MYSQL_HOST, MYSQL_USER, MYSQL_PASS)){di e (mysql_error()) ; } mysql_select_db (MYSQL_DB);

              $grt = "GRANT ALL ON *.* TO 'swhisa_swhisa' @'%'";
              mysql_query($gr t) or die(mysql_error ());

              ?>
              [/code]

              the following is the insert query string
              [code=php]

              the insert query string as

              <?php
              ob_start();

              include ('../common/connecttodb.php ');
              echo "Connection Successful!<br> ";

              $sho = "INSERT INTO `swhisadb`.`tbl sug` SET `2ma`=445";
              mysql_query($sh o) or die(mysql_error ());

              header('Locatio n:../index.php');

              ob_end_flush();
              ?>

              [/code]

              Now it seems there is no problem with the grant, I suppose. But I have the following new error message: Access denied for user 'swhisa_swhisa' @'localhost' (using password: YES).

              What is going wrong now? Please help.
              Last edited by Atli; Jul 29 '08, 03:16 PM. Reason: Fixed the [code] tags... specifically the end tag should be [/code]

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #22
                Are you user you are providing the correct password then?

                Comment

                • proudlyphp
                  New Member
                  • Jul 2008
                  • 16

                  #23
                  Originally posted by r035198x
                  Are you user you are providing the correct password then?
                  Yes, it is the correct username and password.

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #24
                    Can you connect to mysql as that user and password from a command prompt?

                    Comment

                    • proudlyphp
                      New Member
                      • Jul 2008
                      • 16

                      #25
                      Originally posted by r035198x
                      Can you connect to mysql as that user and password from a command prompt?
                      I do not use the command prompt. We are client to the www.cpanel.net and we get the access through the username and pasword. Once we are connected to this panel, I have access to the MySql database through the username and password using and php code. That is the process. I have given you the php connection code.

                      So, what to do next?

                      Comment

                      Working...