PHP code: No error message but not working.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • proudlyphp
    New Member
    • Jul 2008
    • 16

    PHP code: No error message but not working.

    I have no error message coming but the following code does not enter the trialentry into my table tblsug. The code is the following:

    [code=php]

    <?php

    ob_start();

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


    $sql = 'INSERT INTO tblsug(`2ma`) VALUES (\'trialentry\' );';
    mysql_query('$s ql');


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

    ?>
    [/code]

    I have even changed the $sql statement into the following and tried.
    [code=php]
    $sql = 'INSERT INTO tblsug(`2ma`) VALUES (\'trialentry\' )';
    [/code]
    Nothing worked without even poping up error message.

    Please help. I spend considerabel time on this.
  • KlNTARO
    New Member
    • Jul 2008
    • 4

    #2
    Line 9 is your error. Try replacing it with this:

    $sql = "INSERT INTO tblsug ('2ma') VALUES ('\'trialentry\ '')";

    *make sure to copy/paste that; there are some asteriks' that look like quotations

    If that doesn't work, you should at the very least get an error message, instead of nothing.

    Comment

    • Gulzor
      New Member
      • Jul 2008
      • 27

      #3
      Originally posted by proudlyphp
      I have no error message coming but the following code does not enter the trialentry into my table tblsug. The code is the following:

      [code=php]

      <?php

      ob_start();

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


      $sql = 'INSERT INTO tblsug(`2ma`) VALUES (\'trialentry\' );';
      mysql_query('$s ql');


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

      ?>
      [/code]

      I have even changed the $sql statement into the following and tried.
      [code=php]
      $sql = 'INSERT INTO tblsug(`2ma`) VALUES (\'trialentry\' )';
      [/code]
      Nothing worked without even poping up error message.

      Please help. I spend considerabel time on this.
      at line 10 :

      do not surround $sql with single quotes. remove them and see what happens.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Add an or die to your mysql_query statement.

        [php]
        mysql_query($sq l) or die(mysql_error ());
        [/php]

        Comment

        • proudlyphp
          New Member
          • Jul 2008
          • 16

          #5
          Originally posted by markusn00b
          Add an or die to your mysql_query statement.

          [php]
          mysql_query($sq l) or die(mysql_error ());
          [/php]
          Yes, now I got the error message with mysql_error() function. Thanks. And now the error message has come as it is below.

          Connection Successful!
          INSERT command denied to user 'swhisa_swhisa' @'localhost' for table 'tblsug'

          I have logged remotely to the hosting server and set the line together with user and password as define('MYSQL_H OST','localhost ');

          The php code that is giving the error message above is

          [code=php]

          <?php

          ob_start();

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

          $sql = "INSERT INTO `swhisadb`.`tbl sug` (`2ma`) VALUES ('\'trialentry\ '')";
          mysql_query($sq l) or die(mysql_error ());

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

          ?>

          [/code]

          Comment

          • proudlyphp
            New Member
            • Jul 2008
            • 16

            #6
            Thanks a lot for the support.
            Yes, now I got the error message with mysql_error() function. Thanks. And now the error message has come as it is below.

            Connection Successful!
            INSERT command denied to user 'swhisa_swhisa' @'localhost' for table 'tblsug'

            I have logged remotely to the hosting server and set the line together with user and password as define('MYSQL_H OST','localhost ');

            The php code that is giving the error message above is

            [code=php]

            <?php

            ob_start();

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

            $sql = "INSERT INTO `swhisadb`.`tbl sug` (`2ma`) VALUES ('\'trialentry\ '')";
            mysql_query($sq l) or die(mysql_error ());

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

            ?>

            [/code]

            What is the problem now? What does the error message mean? Why the INSERT command is denied?

            Please help.

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Originally posted by proudlyphp
              Thanks a lot for the support.
              Yes, now I got the error message with mysql_error() function. Thanks. And now the error message has come as it is below.

              Connection Successful!
              INSERT command denied to user 'swhisa_swhisa' @'localhost' for table 'tblsug'

              I have logged remotely to the hosting server and set the line together with user and password as define('MYSQL_H OST','localhost ');

              The php code that is giving the error message above is

              [code=php]

              <?php

              ob_start();

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

              $sql = "INSERT INTO `swhisadb`.`tbl sug` (`2ma`) VALUES ('\'trialentry\ '')";
              mysql_query($sq l) or die(mysql_error ());

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

              ?>

              [/code]

              What is the problem now? What does the error message mean? Why the INSERT command is denied?

              Please help.
              Can you show your connection code? I'm thinking maybe there's a problem with that.

              ps: you should add 'or die(mysql_error ())' to all of your queries while in the production stage to hunt down bugs!

              Comment

              • proudlyphp
                New Member
                • Jul 2008
                • 16

                #8
                Originally posted by markusn00b
                Can you show your connection code? I'm thinking maybe there's a problem with that.

                ps: you should add 'or die(mysql_error ())' to all of your queries while in the production stage to hunt down bugs!

                This is my connection code.

                [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)){
                die (mysql_error()) ;
                }
                mysql_select_db (MYSQL_DB);


                ?>


                [/code]

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by proudlyphp

                  What is the problem now? What does the error message mean? Why the INSERT command is denied?

                  Please help.
                  Because the user does not have priviledges that allow him to insert values into that table when they are connected remotely.

                  Comment

                  • Atli
                    Recognized Expert Expert
                    • Nov 2006
                    • 5062

                    #10
                    Check out the GRANT statement in the manual.

                    Comment

                    • proudlyphp
                      New Member
                      • Jul 2008
                      • 16

                      #11
                      Originally posted by Atli
                      Check out the GRANT statement in the manual.
                      Ok, I went to the privilege section and I selected INSERT, UPDATE, DELETE, SELECT only. I tried the programme again - it's the same error message. Then again, I changed the privilege to ALL, checked the code - the same error message.

                      The error message is the same as:
                      Connection Successful!
                      INSERT command denied to user 'swhisa_canserv er'@'localhost' for table 'tblsug'

                      Please I need help badly. Thank you in advance.

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #12
                        Originally posted by proudlyphp
                        Ok, I went to the privilege section and I selected INSERT, UPDATE, DELETE, SELECT only. I tried the programme again - it's the same error message. Then again, I changed the privilege to ALL, checked the code - the same error message.

                        The error message is the same as:
                        Connection Successful!
                        INSERT command denied to user 'swhisa_canserv er'@'localhost' for table 'tblsug'

                        Please I need help badly. Thank you in advance.
                        Run this first and then try again
                        Code:
                         GRANT SELECT, INSERT ON YourDatabaseName.tblsug TO 'swhisa_canserver'@'%';

                        Comment

                        • proudlyphp
                          New Member
                          • Jul 2008
                          • 16

                          #13
                          Originally posted by r035198x
                          Run this first and then try again
                          Code:
                           GRANT SELECT, INSERT ON YourDatabaseName.tblsug TO 'swhisa_canserver'@'%';
                          It still pops up the following error message.
                          Parse error: syntax error, unexpected T_STRING in /home2/swhisa/public_html/trial/sugadddb.php on line 8


                          My code is

                          [code=php]
                          <?php

                          ob_start();

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

                          GRANT SELECT, INSERT ON swhisa_swhisadb .tblsug TO 'swhisa_canserv er'@'%';
                          $sql = "INSERT INTO `swhisadb`.`myt bl` (`2ale`) VALUES ('\'trialentry\ '')";

                          mysql_query($sq l) or die(mysql_error ());


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

                          ?>


                          [/code]

                          Comment

                          • r035198x
                            MVP
                            • Sep 2006
                            • 13225

                            #14
                            Originally posted by proudlyphp
                            It still pops up the following error message.
                            Parse error: syntax error, unexpected T_STRING in /home2/swhisa/public_html/trial/sugadddb.php on line 8


                            My code is

                            [code=php]
                            <?php

                            ob_start();

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

                            GRANT SELECT, INSERT ON swhisa_swhisadb .tblsug TO 'swhisa_canserv er'@'%';
                            $sql = "INSERT INTO `swhisadb`.`myt bl` (`2ale`) VALUES ('\'trialentry\ '')";

                            mysql_query($sq l) or die(mysql_error ());


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

                            ?>


                            [/code]
                            That surely is invalid. You just took the command I gave you and embedded it at a random location in your code?

                            That command needs to be run against the database by someone with grant priviledges.

                            Comment

                            • proudlyphp
                              New Member
                              • Jul 2008
                              • 16

                              #15
                              Originally posted by r035198x
                              That surely is invalid. You just took the command I gave you and embedded it at a random location in your code?

                              That command needs to be run against the database by someone with grant priviledges.
                              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.

                              Comment

                              Working...