I have read that to prevent SQL injection, all MySQL statements should actually my mysqli and parametered. The above code connects to a database, selects a random 'verbs' row, and then takes the cell that intersects the 'verb' row and the def column (the definition of that verb) using mysql_fetch_assoc
.
What changes would make a random query safe from injection?
$user_name = "name";
$password = "password";
$database = "words";
$server = "host";
$db_handle = mysqli_connect($server, $user_name, $password) or die (mysqli_error($db_handle));
$db_found = mysqli_select_db($db_handle, $database) or die (mysqli_error($db_handle));
$randVerb = mysql_query("SELECT * FROM verbs ORDER BY RAND() LIMIT 1");
$db_field = mysql_fetch_assoc($randVerb);
$definition= $db_field['def'];