I created a custom MySQL function that generates a 15 character random string. When I test the function in phpmyadmin it generates the code fine. However when I run it from PHP it returns an error - "Notice: Undefined index: dex in file.php on line ###".
$sql1 = "select GenerateRand() as dex;";
$result1 = mysqli_query($con,$sql1);
$row1 = mysqli_fetch_row($result1);
echo $sql1 . "| |" . $row1['dex'];
I have tried the following
- using the different mysqli_fetch options but none return a different result.
- checking the query result for errors;
- mysqli_errno($con) returns 0
- mysqli_error($con) returns ""
- mysqli_num_rows($result1) returns 1
- mysqli_num_fields($result1) returns 1
SOLVED
After adding these lines to my code
error_reporting(E_ALL);
ini_set('display_errors', 1);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
I realized that I had not granted my database user the execute PRIVILEGES.
It was still not working so after trying the var_dump again I realized that I needed to be using mysqli_fetch_array if I wanted to use $row['dex'] to retrieve the code.
Thank You all for your ideas.
Thank you for the help everyone!