1
CREATE OR REPLACE FUNCTION adduser(fn character varying,ln character varying,cit character varying,i integer,id integer)
  RETURNS void AS
$BODY$
        BEGIN                
    update tabtow set fname=fn,lname=ln,city=cit,phnum=i where phnum=id;
    select * from tabtow;
        END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION increment(integer)
  OWNER TO postgres;

This is my function, how can I call it in PHP?

I'm trying like this, but it isn't working:

$sql = "update tabtow set fname = '$_REQUEST[fn]', lname = '$_REQUEST[ln]', city = '$_REQUEST[ci]', phnum = $_REQUEST[phnum] where phnum = $_REQUEST[id1]";
$res = pg_query($sql);
2
  • 1
    Please learn about SQL injection. ?fn=';UPDATE%20users%20SET%20password='somethingIknow'-- Commented Oct 12, 2012 at 13:49
  • This. A thousand times this. Also, what's your URL? ;) Commented Oct 12, 2012 at 13:54

1 Answer 1

3

Just call the function:

$sql = 'SELECT adduser($1,$2,$3,$4)';
$res = pg_prepare($dbconn, "my_query", $sql);
$res = pg_execute($dbconn, "my_query", array('a','b','c',1));

And like the commenters above say, don't build your queries by hand - use parameterised queries like above.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.