Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by Phonebuff
at 2024-07-28 10:53:42
Point:100 Replies:14 POST_ID:829141USER_ID:12033
Topic:
PostgreSQL Database;Web Services;PHP Scripting Language
So,
I have an HTML page with a from in it that calls a PHP CGI when the user hits submit. In the form is a select box with a size="5" multiple name="Key" statement.
phpinfo() shows that his is properly passing the select as Key[] to the PHP CGI . An I can get the data $_POST('Key') and process it in the PHP program.
Where my problem starts is trying to pass the Array of keys to a PostgreSQL function through a pg_prepare / pg_execute combination.
I have an HTML page with a from in it that calls a PHP CGI when the user hits submit. In the form is a select box with a size="5" multiple name="Key" statement.
phpinfo() shows that his is properly passing the select as Key[] to the PHP CGI . An I can get the data $_POST('Key') and process it in the PHP program.
Where my problem starts is trying to pass the Array of keys to a PostgreSQL function through a pg_prepare / pg_execute combination.
$return_cde = pg_prepare($conn, "SendKeys", 'select web.sendKeys($1, $2, $3)');.....$return_cde = pg_execute($conn, "SendKeys", array($_POST('Pin'), $userData, $current_user->user_login)); 1:2:3:
I have tried changing the prepare and execute a dozen different ways an received a dozen differ errors.
The PostgreSQL function looks like this --
CREATE OR REPLACE FUNCTION web.sendKeys(web_targets_ integer[], web_test_ text, web_user_ text) RETURNS integer As$BODY$DECLARE value integer := NULL;" 1:2:3:4:
TIA -- Fir any direction anyone can offer --
Author: Phonebuff replied at 2024-08-04 02:17:10
Correct answer for the specific question was derived elsewhere, posted here for documentation purposes.
Accepted Solution
Author: Phonebuff replied at 2024-07-30 10:08:36
So the correct answer is to reformat the PHP data into a PostgreSQL array and pass that variable.
$userKey = "{".implode(",",array_map("intval", $userKey))."}";
An then pass $userKey in the Array for $1.
$return = pg_query($conn, "select web.sendKeys($userKey, $userMsgE, $userLoginE)");
$userKey = "{".implode(",",array_map("intval", $userKey))."}";
An then pass $userKey in the Array for $1.
$return = pg_query($conn, "select web.sendKeys($userKey, $userMsgE, $userLoginE)");
Author: Phonebuff replied at 2024-07-28 16:30:16
The problem is passing a PHP arrary to a PostgreSQL Arrary --
I see lot's of hits with Google searches but no answers yet --
================
I see lot's of hits with Google searches but no answers yet --
================
Author: Phonebuff replied at 2024-07-28 12:46:34
Okay,
So in this case it appears to have passed (Array, Text String, Text String) according to the tail on the postgreSQL system..
So in this case it appears to have passed (Array, Text String, Text String) according to the tail on the postgreSQL system..
$userMsgE = pg_escape_string($userMsg); $userLoginE = pg_escape_string($current_user->user_login); $return = pg_query($conn, "select web.sendKeys($userKey, $userMsgE, $userLoginE)"); 1:2:3:4:
ERROR: syntax error at or near "," at character 26
STATEMENT: select web.sendKeys(Array, ergewgrewgewgwerg / XXX, JSXXXXXX)
Expert: duncanb7 replied at 2024-07-28 12:23:47
I mean try simple example first and it will help to narrow down the bug,
Duncan
Duncan
Expert: duncanb7 replied at 2024-07-28 12:22:36
Just think about the input "->" is okay or not ,
Could you put the exact value into put pg_execute() to test pg_execute is okay on sql database ?
PostpreSql sometimes have different declaration writing syntax tolerance from mysql or other sql
Duncan
Could you put the exact value into put pg_execute() to test pg_execute is okay on sql database ?
PostpreSql sometimes have different declaration writing syntax tolerance from mysql or other sql
Duncan
Author: Phonebuff replied at 2024-07-28 12:18:35
Dave,
The pg_execute has 3 and the statement has 3 .. The connection, and the Reference and the array() of values to be passed. The problem is that the first element of the array is also an array. I think thinking I need to unnest it and pass it that way..
Duncan,
I am passing (or at least trying to) array(array, string, string) which is what the PostgreSQL function wants. Changing the order kind of makes a mess of some documentation and standards in a function that has been used for years within the postgresql database. Are you suggesting array(text, text, array) will make a difference ?
The pg_execute has 3 and the statement has 3 .. The connection, and the Reference and the array() of values to be passed. The problem is that the first element of the array is also an array. I think thinking I need to unnest it and pass it that way..
Duncan,
I am passing (or at least trying to) array(array, string, string) which is what the PostgreSQL function wants. Changing the order kind of makes a mess of some documentation and standards in a function that has been used for years within the postgresql database. Are you suggesting array(text, text, array) will make a difference ?
Expert: Dave Baldwin replied at 2024-07-28 12:11:38
The 'pg_execute' page only shows 3 parameters and your statement above has 5.
http://us2.php.net/manual/en/function.pg-execute.php
http://us2.php.net/manual/en/function.pg-execute.php
Expert: duncanb7 replied at 2024-07-28 12:10:29
COuld you put $current_user->user_login as variable first ? something like that
$a=$current_user['user_login'] //example only
echo $a //to see that is what you want
and put it into pg_execute if okay
Duncan
$a=$current_user['user_login'] //example only
echo $a //to see that is what you want
and put it into pg_execute if okay
Duncan
Author: Phonebuff replied at 2024-07-28 12:04:22
Okay,
Get this --
userKey is array
userMsg is string
user_Login is string
Warning: pg_execute() [function.pg-execute]: Query failed: ERROR: array value must start with "{" or dimension information in /home/dxxxxxxxxx/public_html/xxxxxxxx/cgi-bin/xxxxcgi.php on line 87
$return_cde = pg_execute($conn, "SendKeys", array($userKey, $userMsg, $current_user->user_login));
Get this --
userKey is array
userMsg is string
user_Login is string
Warning: pg_execute() [function.pg-execute]: Query failed: ERROR: array value must start with "{" or dimension information in /home/dxxxxxxxxx/public_html/xxxxxxxx/cgi-bin/xxxxcgi.php on line 87
$return_cde = pg_execute($conn, "SendKeys", array($userKey, $userMsg, $current_user->user_login));
Assisted Solution
Expert: duncanb7 replied at 2024-07-28 11:51:48
100 points EXCELLENT
you can use gettype() php to check all input variable type first at http://php.net/manual/en/function.gettype.php and there is a lot related function at the bottom page and make sure it is matched to your SQL database varible type
Duncan
Duncan
Expert: duncanb7 replied at 2024-07-28 11:47:59
pg_execute has error, right ? if so, variable passing into web.sendKeys is matched or confilict.
and pg_prepare is no any error at all ?
Please put more echo statement to find out each code is error first
Duncan
and pg_prepare is no any error at all ?
Please put more echo statement to find out each code is error first
Duncan
Author: Phonebuff replied at 2024-07-28 11:32:37
Duncan,
First off my php is runinng as a result of a form post not embedded in the html..
So ---
<form action="/cgi-bin/xxxicgi.php" method="post" name="FrontPage_Form1" id="pagemsg" onsubmit="return autocomplete="off" FrontPage_Form1_Validator(this)">
<select id="targetGroups" class="targetSubselect" size="5" multiple name="Key[]" width="40" style="width: 400px">
==============================================================================================
The php cgi has no problem with the array Key
$mySelected=$_POST['Key']
echo "<br>You chose:<br>";
foreach ($mySelected as $item)
echo $item."<br>";
But when I try to pass the array key to to the PostgreSQL function I get various errors depending on how and where I place the brackets or casts. But nothing seems to work ..
----------------------------------
First off my php is runinng as a result of a form post not embedded in the html..
So ---
<form action="/cgi-bin/xxxicgi.php" method="post" name="FrontPage_Form1" id="pagemsg" onsubmit="return autocomplete="off" FrontPage_Form1_Validator(this)">
<select id="targetGroups" class="targetSubselect" size="5" multiple name="Key[]" width="40" style="width: 400px">
==============================================================================================
The php cgi has no problem with the array Key
$mySelected=$_POST['Key']
echo "<br>You chose:<br>";
foreach ($mySelected as $item)
echo $item."<br>";
But when I try to pass the array key to to the PostgreSQL function I get various errors depending on how and where I place the brackets or casts. But nothing seems to work ..
----------------------------------
Expert: duncanb7 replied at 2024-07-28 11:22:39
Could your provide more code from your html form, php to parser $_POST with key array and all PostpreSQL code ?
I don't find any "?" character in your question post so I guess you need PostpreSQL and PHP tutorial at
this http://www.designmagick.com/article/9/Starting-Out/Adding-data-to-your-database, Right ?
Hope understand your question completely .If not, pls pt it out and write it in detail
Duncan
I don't find any "?" character in your question post so I guess you need PostpreSQL and PHP tutorial at
this http://www.designmagick.com/article/9/Starting-Out/Adding-data-to-your-database, Right ?
Hope understand your question completely .If not, pls pt it out and write it in detail
Duncan