parameterized queries in php with a phpmyadmin connection

As noted in the comments above, you adjust your function to accept the category as a parameter to the function, then you can call it and use it anywhere in your script:

function muestraProd($id, $DB)
        return null;
    $stmt = $DB->prepare('SELECT * FROM producto WHERE categoria_id = ?');
    return $stmt->fetchAll();

Now that your function accepts the id as a parameter, you can use it where ever, as long as you include this function in your script. On form submit:

# This will insert the id assuming it is submitted in a form
$prod = muestraProd(($_POST['id'])?? false, $DB);

If in a query (as noted in comments)

$prod = muestraProd(($_GET['id'])?? false, $DB);

Then you can just manually if you wanted to:

$prod = muestraProd(1, $DB);

These are the most common ways.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top