Hi there everyone!
I've gotten into the habit of using a numerical id in my query results so if there's an error of any sort, it doesn't give away any information but spits out a numerical string that I can later search the files for to find the issue.
So my result string looks like this:
$r_linkexist = mysqli_query($link, $q_linkexist) or die('Catastrophic failure [Error code: 8959412]');
and if someone reports it, I search my files for that number, then change the result to print the mysqli_error to find out what the problem is.
What I'd like to do though is have the result automatically show me the error, otherwise print the error code. I tried a bunch of methods but I can only really get this lotso code to do it:
$sqlerror_id = '4787208';
if($viewing_user == '1'){
$r_topics = mysqli_query($link, $q_topics) or die(mysqli_error($link).'<br><hr><br>'.$q_topics);
}else{
$r_topics = mysqli_query($link, $q_topics) or die('Catastrophic failure [Error code: '.$sqlerror_id.']');
}
Which leaves me changing a lot of info as I reuse my code elsewhere in the page but I tried less verbose methods, which all failed. Something like:
$sqlerror_id = '4787208' && $sqlerror = 'mysqli_error($sql.'<br><hr><br>'.$q_topics)'; if($viewing_user != '1'){$sqlerror = 'Error code: '.$sqlerror_id);}
$r_topics = mysqli_query($link, $q_topics) or die($sqlerror);
I'm just wondering if any of the people who actually know what in the hell they're doing might be able to give me a minimal snippet that would do this but allow me to reuse with the least amount of modification with other queries.
Thanks for your time!