Hi,
Is this code sound now ? I got a little help.
[code]
ini_set(‘display_errors’,1);
ini_set(‘display_startup_errors’,1);
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
$conn = mysqli_connect(“localhost”,”root”,””,”gulf”); //mysqli_connect(“server”,”user”,”password”,”db”);
$input_1 = ‘here’; //keyword
$input_2 = ‘search here’; //keyphrase
$sql = “SELECT domain from links WHERE keyword = ? OR keyphrase = ?”;
$stmt = mysqli_stmt_init($conn);
if(mysqli_stmt_prepare($stmt,$sql))
{
mysqli_stmt_bind_param($stmt,”ss”,$input_1,$input_2);
mysqli_stmt_execute($stmt);
if(!mysqli_stmt_bind_result($stmt,$output_1)) //mysqli_bind_result() need to be written once. Do not put inside any loop. https://stackoverflow.com/questions/67252495/on-which-line-to-check-if-data-fetching-successful-or-not-when-using-mysqli-stmt/67252635#67252635
{
die(‘Unable to securely query the database!’);
}
else
{
//Below code source is: https://stackoverflow.com/questions/67252495/on-which-line-to-check-if-data-fetching-successful-or-not-when-using-mysqli-stmt/67252635#67252635
$fetchResult = null;
while ($fetchResult = mysqli_stmt_fetch($stmt))
{
echo “$output_1<br>”;
}
/* dont forget to use 3 equal signs to also compare variable type */
/* null == false values are considered the same */
/* null === false this also compare variable types, here types are not the same */
if ($fetchResult === false)
{
die(“mysqli_stmt_fetch failed !”);
}
}
}
else
{
echo ‘Mysqli Error: ‘ .mysqli_stmt_error();
echo ‘<br>’;
echo ‘Mysqli Error No: ‘ .mysqli_stmt_errno();
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
I need to put checking points at appropriate places./lines and not check in wrong lines if data fetching was successful or not.