Got something cool to share with AppGini users? Feel free to post it here!
-
D Oliveira
- AppGini Super Hero
- Posts: 348
- Joined: 2018-03-04 09:30
- Location: David
Post
by D Oliveira » 2022-08-05 23:13
hey guys, can anyone help me figure out why it is returning 500 error?
js
Code: Select all
var pass_val = $j('#tender1-container').val();
var tblname = 'workbook';
$j.ajax({
url: 'hooks/ajax/ajax-po.php',
data: { ajax_pass: pass_val, ajax_pass1: tblname },
success: function(data){
if (data) {
console.log(data);
var tbl = jQuery.parseJSON(data);
if(tbl){
$j('#ct_name').val(tbl.ct_name);
$j('#ct_subdiv').val(tbl.subdivname);
};
}else{
console.log('no data');
}
}
});
php
Code: Select all
<?php
$currDir = dirname(__FILE__) . '/../..'; // use /.. for hooks
include("$currDir/defaultLang.php");
include("$currDir/language.php");
include("$currDir/lib.php");
$con = mysqli_connect($dbServer, $dbUsername, $dbPassword);
mysqli_select_db($con,$dbDatabase);
/* grant access to all users who have acess to the orders table */
$mi = getMemberInfo();
$admin_config = config('adminConfig');
$ajax_pass = makesafe($_REQUEST['ajax_pass']);
$ajax_pass1 = makesafe($_REQUEST['ajax_pass1']);
$query_start = mysqli_query($con,"SELECT * FROM '{$ajax_pass1}' WHERE ID = '{$ajax_pass}'");
$query_done = mysqli_fetch_array($query_start);
echo json_encode($query_done);
?>
-
D Oliveira
- AppGini Super Hero
- Posts: 348
- Joined: 2018-03-04 09:30
- Location: David
Post
by D Oliveira » 2022-08-06 12:37
this is weird because sqlValue() works but that not efficient ( field by field.... ) using mtsqli_fetch_array() would save way more time returning all values, if anyone knows how to fix this please share, in the meanwhile the following code works but you will have to query every field...
Code: Select all
$query_start = "SELECT field FROM {$ajax_var1} WHERE ID = {$ajax_var2} ";
$query_done = sqlValue($query_start);
echo $query_done;
-
D Oliveira
- AppGini Super Hero
- Posts: 348
- Joined: 2018-03-04 09:30
- Location: David
Post
by D Oliveira » 2022-08-06 13:02
still not ideal but that way you dont need multiple ajax files:
Code: Select all
$ajax_pass = makeSafe($_REQUEST['ajax_pass']);
$ajax_pass1 = makeSafe($_REQUEST['ajax_pass1']);
$ajax_pass2 = makeSafe($_REQUEST['ajax_pass2']);
$ajax_pass3 = makeSafe($_REQUEST['ajax_pass3']);
$query_start = "SELECT ct_name FROM {$ajax_pass1} WHERE ID = {$ajax_pass} ";
$query_done = sqlValue($query_start);
$query_start2 = "SELECT subdivname FROM {$ajax_pass3} WHERE ID = {$ajax_pass2} ";
$query_done2 = sqlValue($query_start2);
$arr = array(
"ct_name" => $query_done1,
"subdivname" => $query_done2
);
echo json_encode($arr);
-
pbottcher
- AppGini Super Hero
- Posts: 1638
- Joined: 2018-04-01 10:12
Post
by pbottcher » 2022-08-06 15:09
Hi David,
not sure, but can you check that you pass a value to the ajax call
Code: Select all
var pass_val = $j('#tender1-container').val();
console.log("value : "+pass_val);
var tblname = 'workbook';
$j.ajax({
url: 'hooks/ajax/ajax-po.php',
data: { ajax_pass: pass_val, ajax_pass1: tblname },
success: function(data){
if (data) {
console.log(data);
var tbl = jQuery.parseJSON(data);
if(tbl){
$j('#ct_name').val(tbl.ct_name);
$j('#ct_subdiv').val(tbl.subdivname);
};
}else{
console.log('no data');
}
}
});
also for you php why not use the standard calls?
Code: Select all
<?php
$currDir = dirname(__FILE__) . '/../..'; // use /.. for hooks
include("$currDir/defaultLang.php");
include("$currDir/language.php");
include("$currDir/lib.php");
/* grant access to all users who have acess to the orders table */
$mi = getMemberInfo();
$admin_config = config('adminConfig');
$ajax_pass = makesafe($_REQUEST['ajax_pass']);
$ajax_pass1 = makesafe($_REQUEST['ajax_pass1']);
$resp = sql("SELECT * FROM '{$ajax_pass1}' WHERE ID = '{$ajax_pass}'");
$query_done = db_fetch_assoc($resp);
echo json_encode($query_done);
?>
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
Post
by D Oliveira » 2022-08-06 17:16
Hi there, thank you for replying =) I'm still getting status 500 with this code, it seems to only work when using sqlValue() all other functions keep returning 500
Code: Select all
jquery-3.5.1.min.js:2
GET http://localhost/tigercontrol2/hooks/ajax/ajax-po.php?ajax_pass=6&ajax_pass1=workbook_gutter 500 (Internal Server Error)
-
pbottcher
- AppGini Super Hero
- Posts: 1638
- Joined: 2018-04-01 10:12
Post
by pbottcher » 2022-08-06 17:46
ok,
sorry, did not pay attention to the query
use
Code: Select all
$resp = sql("SELECT * FROM {$ajax_pass1} WHERE ID = '{$ajax_pass}'");
instead
Code: Select all
$resp = sql("SELECT * FROM '{$ajax_pass1}' WHERE ID = '{$ajax_pass}'");
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.
-
jsetzer
- AppGini Super Hero
- Posts: 1817
- Joined: 2018-07-06 06:03
- Location: Kiel, Germany
-
Contact:
Post
by jsetzer » 2022-08-06 17:59
Don't know if it helps on that specific problem:
sql('SQL COMMAND', $eo);
requires $error
variable as 2nd parameter. Maybe 500 is being raised due to missing parameter in given PHP version (behaviour could be different depending on PHP version).
If I remember right, this is different from sqlValue()
-function with optional $error
variable. This could possibly explain why it is working with sqlValue()
-, but not with sql()
-function call.
Last edited by
jsetzer on 2022-08-06 18:03, edited 1 time in total.
Kind regards,
<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 readability
AppGini 24.10 Revision 1579 + all AppGini Helper tools
-
jsetzer
- AppGini Super Hero
- Posts: 1817
- Joined: 2018-07-06 06:03
- Location: Kiel, Germany
-
Contact:
Post
by jsetzer » 2022-08-06 18:02
Just checked code (of AG 22.14)
sql()-Function
Requires 2nd parameter $o
Code: Select all
function sql($statement, &$o) {
// ...
}
sqlValue()-function
Optional 2nd parameter, defaults to NULL
Code: Select all
function sqlValue($statement, &$error = NULL) {
// ...
}
Kind regards,
<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 readability
AppGini 24.10 Revision 1579 + all AppGini Helper tools
-
D Oliveira
- AppGini Super Hero
- Posts: 348
- Joined: 2018-03-04 09:30
- Location: David
Post
by D Oliveira » 2022-08-06 18:06
Thank you both for helping, that did it!!! removing the quote and adding second parameter =)))
-
pbottcher
- AppGini Super Hero
- Posts: 1638
- Joined: 2018-04-01 10:12
Post
by pbottcher » 2022-08-06 20:04
perfect,
true, copy paste sometimes is just not enough
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.