JAjax function to copy a string into a mysql record
JAjax function to copy a string into a mysql record
Hello,
I need your help because, after a lot of time, testing different way, I have not found a solution to my problem.
Summarising, on my Appgini application I have a field called wid. It is a nyumber string.
I have to copy it inside a record in the same table in teh same db.
To do this I made two file:
1) Javascript file with Jquery AJAX function to read and copy the string
2) php file to receive the string and save it in the record.
These are the two files:
js:
function copy(){
var wid = document.getElementById("wid");
$j.ajax({
type : 'POST',
url : 'reqhr.php?wid='+wid,
data: {'wid': ("wid")},
success: function(data) {
if (data == 'ok'){
alert('all good');}
else{
alert ('something wrong');
}
}
});
console.log(data)
console.log(wid)
}
{
$j('#command').val($j('#wid').text().trim());
}
$j(function() {
$j(
'<div class="btn-group-vertical btn-group-lg vspacer-lg" style="width: 100%;">' +
'<button id="bc" onclick="copy()" type="button" class="btn btn-primary btn-lg">' +
'<i class="glyphicon glyphicon-list-alt"></i> Check Heart Rate' +
'</button>' +
'</div>'
).appendTo('.detail_view .btn-toolbar');
});
php:
<?php
$code=",08073#";
$codeheart="ACVBPXL,";
$servername = "localhost";
$database = "rsnms";
$username = "nms";
$password = "xxx";
$wid = $_POST["wid"];
if (isset($_POST["wid"])) {
$wid = $_POST["wid"];
}
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
echo $codeheart."".$wid."".$code;
echo $codeheart."".$code;
echo $wid
?>
The js application finds the wid value but doesn't send anything to the PHP file.
Coudl you help me please to understand where I'm making a mistake?
Thank you very much indeed
Have a nice day
I need your help because, after a lot of time, testing different way, I have not found a solution to my problem.
Summarising, on my Appgini application I have a field called wid. It is a nyumber string.
I have to copy it inside a record in the same table in teh same db.
To do this I made two file:
1) Javascript file with Jquery AJAX function to read and copy the string
2) php file to receive the string and save it in the record.
These are the two files:
js:
function copy(){
var wid = document.getElementById("wid");
$j.ajax({
type : 'POST',
url : 'reqhr.php?wid='+wid,
data: {'wid': ("wid")},
success: function(data) {
if (data == 'ok'){
alert('all good');}
else{
alert ('something wrong');
}
}
});
console.log(data)
console.log(wid)
}
{
$j('#command').val($j('#wid').text().trim());
}
$j(function() {
$j(
'<div class="btn-group-vertical btn-group-lg vspacer-lg" style="width: 100%;">' +
'<button id="bc" onclick="copy()" type="button" class="btn btn-primary btn-lg">' +
'<i class="glyphicon glyphicon-list-alt"></i> Check Heart Rate' +
'</button>' +
'</div>'
).appendTo('.detail_view .btn-toolbar');
});
php:
<?php
$code=",08073#";
$codeheart="ACVBPXL,";
$servername = "localhost";
$database = "rsnms";
$username = "nms";
$password = "xxx";
$wid = $_POST["wid"];
if (isset($_POST["wid"])) {
$wid = $_POST["wid"];
}
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
echo $codeheart."".$wid."".$code;
echo $codeheart."".$code;
echo $wid
?>
The js application finds the wid value but doesn't send anything to the PHP file.
Coudl you help me please to understand where I'm making a mistake?
Thank you very much indeed
Have a nice day
Re: JAjax function to copy a string into a mysql record
Hi,
your
var wid = document.getElementById("wid");
gets the object, but not the value.
Try
var wid = document.getElementById("wid").value;
your
var wid = document.getElementById("wid");
gets the object, but not the value.
Try
var wid = document.getElementById("wid").value;
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: JAjax function to copy a string into a mysql record
Thank you for your answer.
The problem is the wid it is a variable. It is not a fixed value
How can I solve this?
Thank you for your help
Davide
The problem is the wid it is a variable. It is not a fixed value
How can I solve this?
Thank you for your help
Davide
Re: JAjax function to copy a string into a mysql record
Hi,
I would have assumed that it is a variable, why would you try to read it's value otherwise.
So where is your problem? You have a button to call the copy js function. That one would read the variable and call the php via ajax.
your ajax call is a bit strange as you do a mixed post and get request.
Also the way you pass the data is strange
type : 'POST',
url : 'reqhr.php?wid='+wid,
data: {'wid': ("wid")},
try
type : 'POST',
url : 'reqhr.php,
data: {wid: wid},
I would have assumed that it is a variable, why would you try to read it's value otherwise.
So where is your problem? You have a button to call the copy js function. That one would read the variable and call the php via ajax.
your ajax call is a bit strange as you do a mixed post and get request.
Also the way you pass the data is strange
type : 'POST',
url : 'reqhr.php?wid='+wid,
data: {'wid': ("wid")},
try
type : 'POST',
url : 'reqhr.php,
data: {wid: wid},
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: JAjax function to copy a string into a mysql record
Thank you my friend I did this and the result at the end is OK about the js but nohing arrives ti the PHP.
echo $wid = nothing
What can I do??
I tried a lot of different configurations about js and PHP but always teh same result.
Thank you
echo $wid = nothing
What can I do??
I tried a lot of different configurations about js and PHP but always teh same result.
Thank you
Re: JAjax function to copy a string into a mysql record
Hi,
try
JS:
function copy() {
var wid=$j('#wid').val();
$j.ajax({
type : 'POST',
url : 'reqhr.php',
data: {wid: wid},
success: function(data) {
alert(data);}
});
}
PHP: reqhr.php
<?php
echo $_POST['wid'];
this should alert the data that is in wid.
try
JS:
function copy() {
var wid=$j('#wid').val();
$j.ajax({
type : 'POST',
url : 'reqhr.php',
data: {wid: wid},
success: function(data) {
alert(data);}
});
}
PHP: reqhr.php
<?php
echo $_POST['wid'];
this should alert the data that is in wid.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
- D Oliveira
- AppGini Super Hero
- Posts: 348
- Joined: 2018-03-04 09:30
- Location: David
Re: JAjax function to copy a string into a mysql record
worth noting if you use that variable to insert a value in the database always use makeSafe() function to prevent SQL vulnerability
Re: JAjax function to copy a string into a mysql record
Hi,
thank you for your answer,
unfortunatley the resul on js is a empty window on alarm window.
Using this:
function copy(){
var wid = document.getElementById("wid").value;
$j.ajax({
type: 'POST',
url: 'hooks/reqhr.php',
data: {wid: wid},
cache: false,
success: function(copy){
alert(wid);
}
});
}
I have the wid value inside the alarm window, but if it is the data the value sent. This is the reason because I have nothing in the php file
;-( .-(
thank you for your answer,
unfortunatley the resul on js is a empty window on alarm window.
Using this:
function copy(){
var wid = document.getElementById("wid").value;
$j.ajax({
type: 'POST',
url: 'hooks/reqhr.php',
data: {wid: wid},
cache: false,
success: function(copy){
alert(wid);
}
});
}
I have the wid value inside the alarm window, but if it is the data the value sent. This is the reason because I have nothing in the php file
;-( .-(
Re: JAjax function to copy a string into a mysql record
Maybe I'm writing a stupid thing but...
If I use the javascript to make the buttons and I use PHP for everything else??
If I use the javascript to make the buttons and I use PHP for everything else??
Re: JAjax function to copy a string into a mysql record
Hi,
just try the code I gave you. Don't modify it.
your code will of course not outpout anything as the wid is not defined within the success function.
just try the code I gave you. Don't modify it.
your code will of course not outpout anything as the wid is not defined within the success function.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: JAjax function to copy a string into a mysql record
I tried yours and the result is a blank window in the js part
to be exact . Nothing happens no window appear and nothig in th ephp part as well
to be exact . Nothing happens no window appear and nothig in th ephp part as well
Re: JAjax function to copy a string into a mysql record
I modified the js addind a directory in the js file like this:
function copy() {
var wid=$j('#wid').val();
$j.ajax({
type : 'POST',
url : 'hooks/reqhr1.php',
data: {wid: wid},
success: function(data) {
alert(data);}
});
}
console.log(wid)
$j(function() {
$j(
'<div class="btn-group-vertical btn-group-lg vspacer-lg" style="width: 100%;">' +
'<button id="bc" onclick="copy()" type="button" class="btn btn-primary btn-lg">' +
'<i class="glyphicon glyphicon-list-alt"></i> Check Heart Rate' +
'</button>' +
'</div>'
).appendTo('.detail_view .btn-toolbar');
});
and now the window with wid is appeared but nothing happens in the PHP part
function copy() {
var wid=$j('#wid').val();
$j.ajax({
type : 'POST',
url : 'hooks/reqhr1.php',
data: {wid: wid},
success: function(data) {
alert(data);}
});
}
console.log(wid)
$j(function() {
$j(
'<div class="btn-group-vertical btn-group-lg vspacer-lg" style="width: 100%;">' +
'<button id="bc" onclick="copy()" type="button" class="btn btn-primary btn-lg">' +
'<i class="glyphicon glyphicon-list-alt"></i> Check Heart Rate' +
'</button>' +
'</div>'
).appendTo('.detail_view .btn-toolbar');
});
and now the window with wid is appeared but nothing happens in the PHP part
Re: JAjax function to copy a string into a mysql record
after restarting of everything, the resut is:
blank window on JS and nothing on reqhr1.php
blank window on JS and nothing on reqhr1.php
Re: JAjax function to copy a string into a mysql record
Hi,
what is your reqhr1.php? What would you expect it to do?
So currently if you click on the "Check Heart Rate" button a blank pop-up appears, correct?
what is your reqhr1.php? What would you expect it to do?
So currently if you click on the "Check Heart Rate" button a blank pop-up appears, correct?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: JAjax function to copy a string into a mysql record
Yes it is correct. I need to copy the wid value on reqhr1.php
I have to merge three different values to make a string command inside the string field.
two of them are always the same but wid depends by the patient.
My final objective is, using reqhr1.php to save the final string composed by the three values inside the string field
Using the complete path on url the alarm window has the wid value inside so it is right, but nothing arrives to req1.php
I have to merge three different values to make a string command inside the string field.
two of them are always the same but wid depends by the patient.
My final objective is, using reqhr1.php to save the final string composed by the three values inside the string field
Using the complete path on url the alarm window has the wid value inside so it is right, but nothing arrives to req1.php
Last edited by dgasparin on 2020-04-05 10:39, edited 1 time in total.
Re: JAjax function to copy a string into a mysql record
can you post the reqhr1.php
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: JAjax function to copy a string into a mysql record
sure
it is yours
<?php
echo $_POST['wid'];
?>
you can find here the result using the complete path
it is yours
<?php
echo $_POST['wid'];
?>
you can find here the result using the complete path
- Attachments
-
- result.PNG (96.87 KiB) Viewed 7980 times
Re: JAjax function to copy a string into a mysql record
You will have to...
echo json_encode($data);
exit();
...in php file
echo json_encode($data);
exit();
...in php file
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: JAjax function to copy a string into a mysql record
I cannot see the wid in your screenshot, which value is it that you copy in that example?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: JAjax function to copy a string into a mysql record
The wid is the value that you see inside the window
Re: JAjax function to copy a string into a mysql record
So everything worked fine. on button click you get the wid value.
So within your reqhr1.php you can now use that value $_POST['wid'] to do what you need.
So within your reqhr1.php you can now use that value $_POST['wid'] to do what you need.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: JAjax function to copy a string into a mysql record
I tried but nothing happens in reqhr1.php
usng this:
<?php
echo $_POST['wid'];
?>
the result is nothing
usng this:
<?php
echo $_POST['wid'];
?>
the result is nothing
Re: JAjax function to copy a string into a mysql record
sorry i forgot a line:
<?php
$wid =$_POST['wid'];
echo $wid;
?>
The result is always nothing
<?php
$wid =$_POST['wid'];
echo $wid;
?>
The result is always nothing
Re: JAjax function to copy a string into a mysql record
Hi,
it just does what it shall do. You call via an ajax function a php script to echo the wid, which is then captured in the success of the ajax call and displayed in the alert box.
My final objective is, using reqhr1.php to save the final string composed by the three values inside the string field
Using the complete path on url the alarm window has the wid value inside so it is right, but nothing arrives to req1.php
So the question is, what are your 3 values that you want to combine to a string and update your database accordingly.
Are you trying to add the data to an exisiting table of your database that holds the app?
You would need to pass the ID (PK) of the record you wand to update to the reqhr1.php file as well, so that you can access the correct record.
Maybe you can post the variables you try to combine and the information of the table where you want to update the data. Then I can try to help further.
it just does what it shall do. You call via an ajax function a php script to echo the wid, which is then captured in the success of the ajax call and displayed in the alert box.
My final objective is, using reqhr1.php to save the final string composed by the three values inside the string field
Using the complete path on url the alarm window has the wid value inside so it is right, but nothing arrives to req1.php
So the question is, what are your 3 values that you want to combine to a string and update your database accordingly.
Are you trying to add the data to an exisiting table of your database that holds the app?
You would need to pass the ID (PK) of the record you wand to update to the reqhr1.php file as well, so that you can access the correct record.
Maybe you can post the variables you try to combine and the information of the table where you want to update the data. Then I can try to help further.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: JAjax function to copy a string into a mysql record
Thank you so much my friend, I really apprciate your help.
The table name is patients and the three fields to concatenate are:
codeh,wid,code
all of them have to be wrote in the same table on command field
That's all
Thank you so much
The table name is patients and the three fields to concatenate are:
codeh,wid,code
all of them have to be wrote in the same table on command field
That's all
Thank you so much