PHP is not supposed to look within strings between single quotes in contrast with within double quotes. However in my mysqli query string I put variables in the single-quoted list of values and it's working - values are transferred from input form into my mysql in XAMPP. This means it must be peering inside single quotes in order to identify that there's a variable there and substitute values in the mysqli query value section, which shouldn't be the case.
I would have thought only double parentheses containing variables would be substituted into the query but in fact just the opposite - they DID NOT work! I was forced to convert them back to single quotes, which shouldn't work but do.
For example, where all PHP variables in the mysql query values section were defined previously from input html form, the following totally works and inserts form data into my database:
$host = 'localhost';
$user = 'root';
$pw = '';
$db = 'aliensdb';
$dbc = mysqli_connect($host, $user, $pw, $db);
$table = 'alien_abductions';
$query = "INSERT INTO $table (
first_name,
last_name,
when_it_happened,
how_long,
how_many,
alien_description,
what_they_did,
fang_spotted,
other,
email)
VALUES (
'$first_name',
'$last_name',
'$when_it_happened',
'$how_long',
'$how_many',
'$alien_description',
'$what_they_did',
'$fang_spotted',
'$other',
'$email'
)";
$result = mysqli_query($dbc, $query) or die('Error querying database.');
mysqli_close($dbc);
That this works and the variables are put into the values successfully inserted as a new row in my database breaks the laws of PHP - or does it? In what cases does PHP violate the 'single parentheses aren't parsed rule' and/or the 'double parentheses are parsed' rule(s)?
Thanks :)