Call a stored procedure from a button in a html5 page

Hi all,
I have a table that looks like the following:
https://postimg.org/image/nfnhfiivv/
When I press the view button, I want to start another page with a stored procedure in it that will bring me the extra data.
The stored proc requires the userName to pass as a parameter,
How would I take the username from the table and pass it in my stored procedure in another class?
Or if there is a better way to do it, how would I do that?

Any help, suggestions or guidance is very appreciated.

Here is my code for the stored Proc:

global $userName;

$sqlForUser = "SPgetUserDetails $userName" ;

$sqlForUser = sqlsrv_query ( $connection, $sqlForUser );
if( $sqlForUser )
{
        echo " Connection to Stored Procedure Successful ";
}
else
{
        echo " Failed to connect with Stored Procedure " ;
        die ( print_r( sqlsrv_errors( ), true ) );
}

Many thanks

You can transfer data from an HTML page to a PHP script via GET and POST, e.g.

http://php.net/manual/en/reserved.variables.post.php

1 Like

Actually you donā€™t call a stored procedure from a button, you use some code running on the server to get the information to the client. I would try using Ajax for this. See https://www.w3schools.com/php/php_ajax_php.asp

So if I have the following in my table view button:
with href = "userDetails.php?id=$row['Name']".

and $userName = $_GET['Name']; in my other class, where and how do I add ā€˜POSTā€™, to my button above?

Thanks

You will get nothing. You need

$userName = $_GET['id'];

If you want to use $_POST, then use a different method when you call the server code. You donā€™t show how your button calls the server code, is it via a form, or is the button a styled href link? If the former, just change the method.

1 Like

Hi droopsnoot,
my code uses a href link.

Then it will be sending the parameters via the $_GET array, I donā€™t think thereā€™s a way to stick with a href link but use $_POST.

1 Like

Thanks again for your help droopsnoot.

Here is what I did:


Then in my next page i use the ā€˜idā€™ like so:

$PayoutID = $_GET [ ā€˜idā€™ ] ;

Then pass it to my stored procedure:

$sqlForDetails= ā€œGetDetails ā€˜$Datedā€™ , $PayoutIDā€ ;

works perfectly.

Thanks again

1 Like

Be aware of SQL Injection

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