Android Question mysql server update error

tufanv

Expert
Licensed User
Longtime 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:

B4X:
<?

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
 

cyiwin

Active Member
Licensed User
Longtime 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:
Upvote 0

tufanv

Expert
Licensed User
Longtime User
I couldnt make it work. But i dont understand while select and insert works fine. Why update does not work
 
Upvote 0

cyiwin

Active Member
Licensed User
Longtime 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?
 
Upvote 0

tufanv

Expert
Licensed User
Longtime 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?

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

tufanv

Expert
Licensed User
Longtime 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?

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
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime 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_handle, date("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);
 
Upvote 0

tufanv

Expert
Licensed User
Longtime 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_handle, date("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);

I am very amateur at php so i dont know what and where to put these loggings :/
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
PHP:
<?
$file_handle = fopen('./b4a.log', 'a+');fwrite($file_handle, "======================================"."\r\n");
foreach($_REQUEST as $name => $value){
  fwrite($file_handle, date("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_handle, date("d.m.Y H:i:s", time()).": SQL =".$sql."\r\n");
$q = mysql_query($sql);
if (!is_resource($q)) {
    fwrite($file_handle, date("d.m.Y H:i:s", time()).": MySQL error =".mysql_error()."\r\n");
} else {
        print json_encode("udated");
}
break;

}
fclose($file_handle);
?>
 
Upvote 0

cimperia

Active Member
Licensed User
Longtime User
I suggest you "expand" and print your SQL query :

B4X:
  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.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
PHP:
<?
$file_handle = fopen('./b4a.log', 'a+');fwrite($file_handle, "======================================"."\r\n");
foreach($_REQUEST as $name => $value){
  fwrite($file_handle, date("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_handle, date("d.m.Y H:i:s", time()).": SQL =".$sql."\r\n");
$q = mysql_query($sql);
if (!is_resource($q)) {
    fwrite($file_handle, date("d.m.Y H:i:s", time()).": MySQL error =".mysql_error()."\r\n");
} else {
        print json_encode("udated");
}
break;

}
fclose($file_handle);
?>

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
 
Upvote 0
Top