Android Question mysql server update error

Discussion in 'Android Questions' started by tufanv, Jul 24, 2015.

  1. tufanv

    tufanv Expert Licensed User

    Hello

    I am conecting my app to remote mysql server. I can use insert and select but with update i have a problem

    In my app I am using :

    reportsending3.download2("https://www.xx.com/connectios.php", Array As String ("action", "updatepuan", "adaminadi3", "feridun","adaminadi4","311"))

    and in my php i have:

    Code:
    <?

    include (
    "dbpushios.php");
    $con = mysql_connect($dbhost,$dbuser,$dbpass) 
    or die(mysql_error());
    mysql_select_db($dbname) 
    or die(mysql_error());
    mysql_query(
    "SET CHARACTER SET utf8");

    $action = $_GET[
    "action"];
    switch ($action)

    {

           
    case "updatepuan":

    $silincek6 = $_GET[
    "adaminadi3"];
    $silincek7 = $_GET[
    "adaminadi4"];

    $q = mysql_query(
    "update tblonline set score='$silincek7' where username='$silincek6'");
            print json_encode(
    "udated");
    break;







       
    }





    ?>

    I get Success for response at jobdone but when i check the mysql entries i see thaat it is not updated. What am i doing wrong ?

    TY
     
  2. cyiwin

    cyiwin Active Member Licensed User

    I think this may forward SQL errors to your B4A log.

    PHP:
    $sql_string "update tblonline set score='$silincek7' where username='$silincek6'";
    $res mysql_query($sql_string) or trigger_error(mysql_error()." in ".$sql_string);
    print 
    json_encode($res);
     
    Last edited: Jul 24, 2015
  3. tufanv

    tufanv Expert Licensed User

    I couldnt make it work. But i dont understand while select and insert works fine. Why update does not work
     
  4. cyiwin

    cyiwin Active Member Licensed User

    I don't know why it isn't working either. In your PHP if you replace everything from case to break with...
    PHP:
    case "updatepuan":

    $silincek6 $_GET["adaminadi3"];
    $silincek7 $_GET["adaminadi4"];

    $sql_string "update tblonline set score='$silincek7' where username='$silincek6'";
    $res mysql_query($sql_string) or trigger_error(mysql_error()." in ".$sql_string);
    print 
    json_encode($res);

    break;
    And in your B4a Jobdone area where you log your Job.GetString you should see "true" if your SQL worked or an error message if it didn't. What does your B4A log say?
     
  5. tufanv

    tufanv Expert Licensed User

    I will give it a try in half an hour and report back . Thank you !
     
  6. tufanv

    tufanv Expert Licensed User

    Yes. I am getting a false on the logs but it does not say anything . This is the log : ( first it says success but than getting a false )

    Application_Start
    response success
    JobName = updatepuanlar, Success = true
    false
    Puan Guncellendi
     
  7. DonManfred

    DonManfred Expert Licensed User

    I suggest putting some logging into your php so you could compare things reading the logfile...

    PHP:
    $file_handle fopen('./b4a.log''a+');
    fwrite($file_handle"======================================"."\r\n");
    foreach(
    $_REQUEST as $name => $value){
        
    fwrite($file_handledate("d.m.Y H:i:s"time()).": ".$name."=".$value." ".$add."\r\n");
    }
    fwrite($file_handle"======================================"."\r\n");
    [...] do 
    logging of your create sql-statement for example
    fclose
    ($file_handle);

     
  8. tufanv

    tufanv Expert Licensed User

    I am very amateur at php so i dont know what and where to put these loggings :/
     
  9. DonManfred

    DonManfred Expert Licensed User

    PHP:
    <?
    $file_handle fopen('./b4a.log''a+');fwrite($file_handle"======================================"."\r\n");
    foreach(
    $_REQUEST as $name => $value){
      
    fwrite($file_handledate("d.m.Y H:i:s"time()).": ".$name."=".$value."\r\n");
    }
    fwrite($file_handle"======================================"."\r\n");
    include (
    "dbpushios.php");
    $con mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error());
    mysql_select_db($dbname) or die(mysql_error());
    mysql_query("SET CHARACTER SET utf8");

    $action $_GET["action"];
    switch (
    $action)

    {

         
    case 
    "updatepuan":

    $silincek6 $_GET["adaminadi3"];
    $silincek7 $_GET["adaminadi4"];
    $sql "update tblonline set score='$silincek7' where username='$silincek6'";
    fwrite($file_handledate("d.m.Y H:i:s"time()).": SQL =".$sql."\r\n");
    $q mysql_query($sql);
    if (!
    is_resource($q)) {
        
    fwrite($file_handledate("d.m.Y H:i:s"time()).": MySQL error =".mysql_error()."\r\n");
    } else {
            print 
    json_encode("udated");
    }
    break;

    }
    fclose($file_handle);
    ?>
     
  10. cimperia

    cimperia Active Member Licensed User

    I suggest you "expand" and print your SQL query :

    Code:
    print  "update tblonline set score='$silincek7' where username='$silincek6'";
    Check that it's what you expected. Run the expanded query directly on your MySql server and see whether it succeeds or not.
     
    tufanv likes this.
  11. tufanv

    tufanv Expert Licensed User

    Yes !! Thank you very much for your effort. I have read the b4a.log file and see that :

    25.07.2015 12:24:16: SQL =update tblonline set score='311' where username='feridun'
    25.07.2015 12:24:16: MySQL error =SELECT command denied to user 'admin_tufanv'@'localhost' for column 'username' in table 'tblonline'

    I had disabled the select permission for this db user. I didnt know that while using update i needed the select permission. ! Regards
     
    DonManfred and cyiwin like this.
Loading...