-1

So I have the following code which is used to add a row to the respondent table, all working except when trying to add the value in of Brand:

$brand = 'Central';

function new_respondent() {
        global $link;
        $proc = mysqli_prepare($link, "INSERT INTO trespondent (brand, code) VALUES (?, uuid());");
        mysqli_stmt_bind_param($proc, "s", $brand);
        mysqli_stmt_execute($proc);
        $respondent_id = mysqli_insert_id($link);
        mysqli_stmt_fetch($proc);
        mysqli_stmt_close($proc);
        mysqli_clean_connection($link);
}

This code works (to a point) adds a row in the table and adds in the UUID no problems but brand is going in as NULL - I'm trying to work out if I am missing something very obvious here!

Any and all suggestion welcome.

Homer_J
  • 3,277
  • 12
  • 45
  • 65

1 Answers1

1

You need to add $brand to your global, since it's outside of the function:

global $link, $brand;

Alternatively, you can modify your function to accept $brand as parameter:

function new_respondent($brand) {
...
}
Niraj Shah
  • 15,087
  • 3
  • 41
  • 60