mysql user

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dave

    mysql user

    Hello,
    I'm trying to create my first php app, and i want it to get it's data
    via a mysql database. In the app i've got a connection file that defines my
    database information and as the mysql root user i did:
    grant all on app.* to appuser@localho st identified by 'password';
    this did not return an error. My appuser can connect to mysql using
    commandline mysql but when i try to use a form to insert data my built-in
    error checks are not tripped leading me to believe that insertion was
    successful, but again from commandline mysql i do a
    select * from table;
    i get an empty set returned. Any help appreciated.
    Thanks.
    Dave.


  • Aggro

    #2
    Re: mysql user

    dave wrote:
    [color=blue]
    > grant all on app.* to appuser@localho st identified by 'password';[/color]

    I see nothing wrong with the grant syntax.
    [color=blue]
    > this did not return an error. My appuser can connect to mysql using
    > commandline mysql but when i try to use a form to insert data my built-in
    > error checks are not tripped leading me to believe that insertion was
    > successful, but again from commandline mysql i do a
    > select * from table;
    > i get an empty set returned. Any help appreciated.[/color]

    A little more information would be nice.

    echo the queries you are using to insert data and copy-paste those here.
    Also from mysql command line, give command "desc yourtablename" which
    will give information about the table structure, copy-paste that also here.

    Also you could copy-paste the line(s) which you are using to establish
    connection to database (and select the database, in case you are doing
    that on another line), to make sure there's no error in there.

    Comment

    • dave

      #3
      Re: mysql user

      Hello,
      Thanks. Here is the additional information.
      For the below information i've changed the databasename, username, and
      password and the $values are passed via a form.

      mysql_connect ('localhost', 'databaseuser', 'databasepasswo rd') ;
      mysql_select_db ('database');

      $sql = "INSERT INTO databasetable (timestamp,titl e,entry) VALUES
      ('$timestamp',' $title','$entry ')";
      $result = mysql_query($sq l) or print ("Can't insert into table
      databasetable.< br />" . $sql . "<br />" . mysql_error());

      if ($result != false)
      {
      print "Your entry has successfully been entered into the database!";
      }

      mysql_close();
      }

      ?>

      Here's my table structure:

      mysql> desc databasetable;
      +-----------+--------------+------+-----+---------+----------------+
      | Field | Type | Null | Key | Default | Extra |
      +-----------+--------------+------+-----+---------+----------------+
      | id | int(20) | | PRI | NULL | auto_increment |
      | timestamp | int(20) | | | 0 | |
      | title | varchar(255) | | | | |
      | entry | longtext | | | | |
      +-----------+--------------+------+-----+---------+----------------+
      4 rows in set (0.00 sec)

      Hope this helps.
      Thanks.
      Dave.


      Comment

      • Aggro

        #4
        Re: mysql user

        dave wrote:
        [color=blue]
        > mysql_connect ('localhost', 'databaseuser', 'databasepasswo rd') ;
        > mysql_select_db ('database');[/color]

        If you didn't change the values for your grant-clause (below)
        [color=blue]
        > grant all on app.* to appuser@localho st identified by 'password';[/color]

        That should be:
        mysql_connect ('localhost', 'appuser', 'password') ;
        mysql_select_db ('app');

        I actually tested your code on my computer (with minor changes), and it
        inserted the row correctly into database and I was able to view it from
        console.

        You could try this code on your computer to see if it works: ( Change
        the database, username and password if you used different values in your
        grant. )

        <?php
        $timestamp = 5;
        $title = "title";
        $entry = "testest";

        mysql_connect ('localhost', 'appuser', 'password') ;
        mysql_select_db ('app');

        $sql = "INSERT INTO databasetable (timestamp,titl e,entry)
        VALUES('$timest amp','$title',' $entry')";
        $result = mysql_query($sq l) or print ("Can't insert into table
        databasetable.< br />" . $sql . "<br />" . mysql$

        if ($result != false)
        {
        print "Your entry has successfully been entered into the database!";
        }

        mysql_close();
        ?>

        Comment

        Working...