Android Question MySql Insert

Discussion in 'Android Questions' started by daniedb, Jul 2, 2015.

  1. daniedb

    daniedb Active Member Licensed User

    Hi Guys

    Working through the excellent tutorial from Erel and some over memebrs using MYSQL to insert/List data in a MySql Database/Table.
    List view work fine, but as soon as I try to Insert a New record it tells me
    Response from server: Access denied for user 'root'@'localhost' (using password: NO)
    Access denied for user 'root'@'localhost' (using password: NO)

    I've got 2 PHP file, get.php for getting the info, and ins.php for inserting.
    The Username/Paths/Password/Database all is entered correctly. Double/Tripple check that

    Can anyone see something wrong in the code. I did give permissions in Phpmyadmin, for domain to access my Database.
    'Activity module
    Sub Process_Globals
    Private LIST_CATCH  As String
    End Sub

    Sub Globals
    Type TwoLines (First As String, Second As String)
    Dim ViewCatchersList As ListView
    Private ExitBtn As Button
    Private NameSurnametxt As EditText
    Private AddressTxt As EditText
    Private AddBtn As Button
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    End Sub
    Sub FetchNamesList
    ProgressDialogShow("Fetching list of Name")
    "SELECT NameSurname, Address FROM catchers ", LIST_CATCH)
    End Sub

    Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
       job.Initialize(JobName, Me)
    "", Query)
    End Sub

    Sub JobDone(Job As HttpJob)
    If Job.Success Then
    Dim res As String
         res = Job.GetString
    Log("Response from server: " & res)
    Dim parser As JSONParser
    Select Job.JobName
    Dim GetCatchList As List
             GetCatchList = parser.NextArray 
    'returns a list with maps
             For i = 0 To GetCatchList.Size - 1
    Dim m As Map
               m = GetCatchList.Get(i)
    'We are using a custom type named TwoLines (declared in Sub Globals).
               'It allows us to later get the two values when the user presses on an item.
               Dim tl As TwoLines
               tl.First = m.Get(
               tl.Second = m.Get(
               ViewCatchersList.AddTwoLines2(tl.First, tl.Second, tl)
    'print the result to the logs
    End Select
    ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    End Sub

    Sub ExitBtn_Click
    End Sub

    Sub AddBtn_Click
    Dim InsCatchers As HttpJob
    ""Array As String("NameSurname", NameSurnametxt.text, "Address", AddressTxt.text))
    End Sub
    PHP Insert code
    $databasehost = 
    $databasename = 
    $databaseusername =
    $databasepassword = 

    $con = mysql_connect($host,$user,$pw) 
    or die(mysql_error());
    or die(mysql_error());
    "SET CHARACTER SET utf8");
    "SET NAMES 'utf8'");

    Address = $_GET["Address"];
    $NameSurname = $_GET[

    $res = mysql_query(
    "Insert into catchers (NameSurname, Address) VALUES ('$NameSurname', $Address)");

    print (
    "I have inserted $NameSurname and $Address in my table");
    I have tried Poststring and Download 2 in Httputils. Same results

  2. sorex

    sorex Expert Licensed User

    did you give access for that user in your database, even better... write (insert) access ?
  3. daniedb

    daniedb Active Member Licensed User

    Hi Sorex,
    Yes I've set privileges to "All" for that user

    What do you mean by "write (insert) acccess"?
  4. Erel

    Erel Administrator Staff Member Licensed User

    It does look like a permission problem. Note that this script is vulnerable to sql injects.
  5. sorex

    sorex Expert Licensed User

    sometimes only the SELECT option is being tagged as granted right.

    but then you would get other errors, I guess either the server address is wrong or the user/pass combination.

    are you sure the database server is the same as the webserver?

    usually they split it up to spread resources.
  6. sorex

    sorex Expert Licensed User

    also check the database name, sometimes they use the user prefix then it will be username_mydb instead of mydb
  7. daniedb

    daniedb Active Member Licensed User

    Hi Sorex. Yip checked that.
    Like I said. The retrieve of data and display in a List works 100%
    I've use the exact connection string in the ins.php code aswell
  8. sorex

    sorex Expert Licensed User

    put an echo of some rubbish before the insert and see if that gets printed.
  9. daniedb

    daniedb Active Member Licensed User

    $databasehost = "localhost";
    $databasename = "db";
    $databaseusername ="user";
    $databasepassword = "pw";

    $con = mysql_connect($host,$user,$pw) or die(mysql_error());

    Wrong variables declared in the connection string.
    Think it's time for Bed, havn't slept for 3 days

    Thanks for the help guys
    mangojack and DonManfred like this.
  10. sorex

    sorex Expert Licensed User

    indeed, LOL
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice