Android Question PHP Fatal error: Uncaught Error

PABLO2013

Well-Known Member
Licensed User
Longtime User
I would appreciate if you can help me with this error ... I have tried to resolve it, but no. Perform a database restore and now it does not connect ... I do not know the reason. it seems that the credentials are correct thanks
B4X:
[28-Sep-2018 08:31:26 America/Los_Angeles] PHP Fatal error:  Uncaught Error: Call to undefined function mysql_connect() in /registro.php:8
Stack trace:
#0 {main}
  thrown in /registro.php on line 8
[28-Sep-2018 08:31:48 America/Los_Angeles] PHP Fatal error:  Uncaught Error: Call to undefined function mysql_connect() in /registro.php:8
Stack trace:
#0 {main}
  thrown in /registro.php on line 8

B4X:
<?

$databasehost = "mysql";
$databasename = "REGISTROxxxxxx";
$databaseusername ="xxxx";
$databasepassword = "xxxxx";

$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
$query = file_get_contents("php://input");
$sth = mysql_query($query);

if (mysql_errno()) {
    header("HTTP/1.1 500 Internal Server Error");
    echo $query.'\n';
    echo mysql_error();
}
else
{
    $rows = array();
    while($r = mysql_fetch_assoc($sth)) {
        $rows[] = $r;
    }
    print json_encode($rows);
}
?>

B4X:
job.PostString("http://www.xxxxxxxr.com/registro.php", Query)

Query = SELECT * FROM AVxxxxxOPRESUPUESTO
 

KMatle

Expert
Licensed User
Longtime User
There were some changes in PHP/MySQL:

B4X:
$con = mysqli_connect($host,$user,$pw) or die(mysqli_error());
    mysqli_select_db($con,$db) or die(mysqli_error());
    mysqli_query($con,"SET CHARACTER SET utf8");
    mysqli_query($con,"SET NAMES 'utf8'");

Note the i

B4X:
mysqli_query

Warning:
This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.
 
Upvote 0

PABLO2013

Well-Known Member
Licensed User
Longtime User
kMatle

kMatle What you tell me is to change

Thanks DonManfred
thanks kMatle

B4X:
$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
$query = file_get_contents("php://input");
$sth = mysql_query($query);

by

B4X:
$con = mysqli_connect($host,$user,$pw) or die(mysqli_error());
    mysqli_select_db($con,$db) or die(mysqli_error());
    mysqli_query($con,"SET CHARACTER SET utf8");
    mysqli_query($con,"SET NAMES 'utf8'");
tks
 
Upvote 0

PABLO2013

Well-Known Member
Licensed User
Longtime User
Thank you this came from an update and restoration of php and phpmyadmin and you are very right, thank you
 
Upvote 0

PABLO2013

Well-Known Member
Licensed User
Longtime User
KMatle sorry, you have a version for this same or example ... no php programming ... thanks
 
Upvote 0

PABLO2013

Well-Known Member
Licensed User
Longtime User
?php

$databasehost = "localhost";
$databasename = "xxxx";
$databaseusername ="xxxx";
$databasepassword = "xxxx";

$con = mysqli_connect($databasehost,$databaseusername,$databasepassword, $databasename) or die(mysqli_error($con));
mysqli_set_charset ($con , "utf8");
$query = file_get_contents("php://input");
$sth = mysqli_query($con, $query);

if (mysqli_errno($con)) {
header("HTTP/1.1 500 Internal Server Error");
echo $query.'\n';
echo mysqli_error($con);
}
else
{
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
$res = json_encode($rows);
echo $res;
mysqli_free_result($sth);
}
mysqli_close($con);
?>
 
Upvote 0

PABLO2013

Well-Known Member
Licensed User
Longtime User
kmatle you say me : Now you must protect the script against SQL injection.

But what is the main idea of this,i check about Prepared Statements, but I do not understand the main idea, could you tell me, thanks.


I tell you to make a small security for my application ... basically take the serial of the device and compare it with serials previously added to the database .. in this case, as would be the general idea of Prepared Statements, if you have a basic example , thank you very much for your help, now my application came back to work a bit unstable ... but I'm trying to see what happens. Thank you
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…