Insert data to MySql

Dear Experts,
I am trying to insert data to mysql.
I have taken following steps

  1. Created cng_insert.php on this location

codes in this files are like this

<?php

$servername = "localhost";
$username = "id30649282_hassanz";
$password = "Ahmad7123456";
$database = "id30649282_asiacng";

$dbc = mysqli_connect($servername, $username, $password, $database);

if(!$dbc) {
die("DATABASE CONNECTION FAILED:" .mysqli_error($dbc));
exit();
}
$p_ltr = mysqli_real_escape_string($dbc, $_GET['p_ltr']);
$p_rat = mysqli_real_escape_string($dbc, $_GET['p_rat']);
$p_amt = mysqli_real_escape_string($dbc, $_GET['p_amt']);
$query = "INSERT INTO sales(p_ltr,p_rat,p_amt)
 VALUES ('$p_ltr','$p_rat','$p_amt')";
if(mysqli_query($dbc, $query)){
echo "Records added successfully";
} 
else{
echo "ERROR: Could not able to execute". $query." ". mysqli_error($dbc);
}
mysqli_close($dbc);
?>
  1. I tested this php as follows

It mean codes are working but not getting values to insert

  1. I used following block
    blocks1
    blocks2

globalTempUrl=https://lettered-manners.000webhostapp.com/cng_insert.php?p_lit=

but I click click submit button then following error occurs

Webpage not available

Please help me what I am doing wrong.

Regards

Well, your answer is in your error message:

Understand why from what data / type you are sending, and what the mysql server is expecting for that column in the table.

Also

image

should these ? be & ?

Also

see HERE

&

http://kio4.com/appinventor/340C_appinventor_mysqli.htm

Sir I have replace ? with & but there is still same issue.

I refer to this link
https://www.newthinktank.com/wp-content/uploads/2014/05/AppInventor22Blocks.png

I am confusing with last line
x
But my codes has this last line

y

The difference is Get and Reload
I could not find property web1.Get

Please

Regards

image

Reload is the wrong block

1 Like

But sir there is not Get in events
w_path

Where to find it?

Regards

You are looking in the Webviewer component, NOT the web component!

1 Like

Sir I followed this link

http://kio4.com/appinventor/340C_appinventor_mysqli.htm

Now my blocks looks like this

https://lettered-manners.000webhostapp.com/cng_insert.php

When I click Submit button then it show this error message
c

On the other side my code work here
e

What I am doing wrong now.
Please

In segment set a space.

2 Likes

You do not appear to have any spaces in your url (orden), so remove the replacement block.

Also, test the Web1.Get url with the same one your tried in the browser ?

1 Like

Thanks for all participants, now my codes work fine, I have following blocks
blocks1

I have a little question again
If data has been saved then there will be Notifier like

Data saved successfully

Please help me to show notifier

Regards

Use the web.gottext event block to return the response content from the server. Display this in your notifier

About replace text...

Instead of using: data-->replace all text

try using:

Web2.Url ---> Web2.UriEncode ----> data
Web2.Get

Sir there is not Web2.UriEncode
z
From where to find it?

Keep searching.

image

the url and parameters to be connected with ?, and each parameter connected with &.
But in your photo I only see &.

it should be like this:
http://aa.com?bb =cc&dd =ee&ff=gg

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.