Android Question web request too long

MohammadNew

Active Member
Licensed User
Longtime User
Hello everyone,

I have problem with insert data

error web request too long > because I insert base64string

B4X:
Dim InsertNewPerson As HttpJob
    InsertNewPerson.Initialize("InsertNewP", Me)
    InsertNewPerson.download2("http://" & ServerIP & "/persons.php", Array As String ("action", "InsertNewPerson", "name", NameET.Text, "age", AgeET.Text, "img",img64))

but without base64string it is done.
 

sorex

Expert
Licensed User
Longtime User
you forgot to quote the $img as it is text!

INSERT INTO persons (name, age, img) VALUES ('$name', $age, '$img')

make sure the age field is a numeric one or you need to quote it aswell
 
Upvote 0

MohammadNew

Active Member
Licensed User
Longtime User
I tried with img and without img nothing happened
B4X:
this work without img
InsertNewPerson.download2("http://" & ServerIP & "/persons.php", Array As String ("action", "InsertNewPerson", "name", NameET.Text, "age", AgeET.Text))

this does not work without img and with img
InsertNewPerson.postString("http://" & ServerIP & "/persons.php","action=InsertNewPerson & name="& NameET.Text &"&age="& AgeET.Text)

I think the problem with "poststring"

I put ' ' in all because text
 
Upvote 0

MohammadNew

Active Member
Licensed User
Longtime User
B4X:
<?php

$host = "my server";
$user = "my user";
$pw = "my pass";
$db = "my db";

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

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

{
    case "CountPersons":
        $q = mysql_query("SELECT * FROM persons");
        $count = mysql_num_rows($q);
        print json_encode($count);
    break;
   
    Case "GetPersons":
        $q = mysql_query("SELECT name, age FROM persons");
        $rows = array();
        while($r = mysql_fetch_assoc($q))
        {
            $rows[] = $r;
        }
        print json_encode($rows);
    break;
   
    case "InsertNewPerson":
        $name = $_POST["name"];
        $age = $_POST["age"];
        $q = mysql_query("INSERT INTO persons (name, age) VALUES ('$name', '$age')");
        print json_encode("Inserted");
    break;
   
}

?>
 
Upvote 0

MohammadNew

Active Member
Licensed User
Longtime User
Now I add in php file this

B4X:
 case "SelectPersons":
        $name = $_POST["name"];
        $age = $_POST["age"];
        $img= $_POST["img"];     
        $q = mysql_query("select * from persons where name='$name'");
        print json_encode("Selected");
    break;

and what should I write select single row

where name=NameET.Text
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
your PHP code needs some work, actually 2 things pop out to me.

For one, your not using MySQLi because mysql_xxxx is deprecated and may not even work at all at this point.

and two, your not using mysqli_escape_string so you will get SQL injection exploited. My advice, watch video courses, or take a course in PHP and PHP/MariaDB/MySQL integration.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
learning is the cure of your problems. if you just copy paste everything each time you'll keep coming back with the same questions since you don't know what's going on.

most of the things you need is just a few lines of code so you don't need to go through 500 pages of php.
 
Upvote 0

MohammadNew

Active Member
Licensed User
Longtime User




Thanks alot

I am going to learn it . I wish get the code .
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…