Hi community I'm testing the functions to add a new Row in the db present on my server, I state that I am a beginner with php codes. I am editing a php script that I take as an example. I replaced the parameters for accessing the server with my access parameters, then I replaced the db with mine and modified the name of the table where I entered the parameters and fields to direct the new row to my db. The problem is that no addition to the db occurs and I get no error from the server and from the json log how can I solve it?
In the server error log this is this:
[13-Nov-2019 12:17:07 UTC] PHP warning: mysqli_error () has exactly 1 parameter, 0 given in /Directory/personsdb.php on line 9
I wanted to clarify that I use PhpMyAdmin for the db in Cpanel and that for reading the rows from my app it works.
SCRIPT PHP
B4a CODE
In the server error log this is this:
[13-Nov-2019 12:17:07 UTC] PHP warning: mysqli_error () has exactly 1 parameter, 0 given in /Directory/personsdb.php on line 9
I wanted to clarify that I use PhpMyAdmin for the db in Cpanel and that for reading the rows from my app it works.
SCRIPT PHP
B4X:
<?php
$host = "localhost";
$user = "xxxxxxx"; //parameters obscured by me
$pw = "xxxxxxxxx;
$db = "xxxxxxxxx";
$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'");
$json = file_get_contents("php://input");
$jsall = array();
$jsone = array();
$jsall=json_decode($json, true);
$jsone=$jsall[0];
$Action = $jsone["Action"];
switch ($Action)
{
Case "InsertPerson":
$pname=stripslashes(mysqli_real_escape_string($con,$jsone["pname"]));
$pbirthdate=stripslashes(mysqli_real_escape_string($con,$jsone["pbirthdate"]));
$stmt = $con->prepare("INSERT INTO Comande (Post,Id) VALUES (?,?)");
$rc=$stmt->bind_param($pname, $pbirthdate);
$rc=$stmt->execute();
break;
default:
print json_encode ("Error: Function not defined (" . $action . ")");
}
?>
B4a CODE
B4X:
Public const Servername As String = "http://www.xxxxxx.com"
Public const ScriptPath As String = "/xxxxx.php"
B4X:
Sub InsertNewPerson (JsonString As String) As ResumableSub
Dim j As HttpJob
j.Initialize("", Me)
j.PostString(Servername & ScriptPath, JsonString)
Wait For (j) JobDone(j As HttpJob)
Log(j.GetString)
Dim Result As String = j.GetString
j.Release
Return Result
End Sub
Sub Button1_Click
Dim id As Int=2
JsonList.Initialize
Dim JsonRow As Map = CreateMap("Action":"InsertPerson","pname":EditText1.Text,"pbirthdate":id)
JsonList.Add(JsonRow)
JsonGenerator.Initialize2(JsonList)
Dim JSONstring As String = JsonGenerator.ToString
Wait For(InsertNewPerson(JSONstring)) Complete (Result As String)
Log(Result)
End Sub
Last edited: