So I'm using PHP to run a SQL command, using PHP variables which get input from an HTML form.
I'm essentially creating a "to-do" list, so the user submits some information on the HTML form, then an SQL command is created, and this SQL command is then stored into a "to-do" table. If the to-do is approved, then the SQL command is stored in the SQL table is then executed.
My issue here is that I am trying to access some of the PHP variables, but in order to successfully store an SQL statement within another one I have to use the double quotes for the text being passed in, otherwise, it just shows the PHP variable.
This is my code:
$ownername = trim(filter_input(INPUT_POST, 'ownername'));
$owner = trim(filter_input(INPUT_POST, 'street'));
$city = trim(filter_input(INPUT_POST, 'city'));
$country = trim(filter_input(INPUT_POST, 'country'));
$paying = trim(filter_input(INPUT_POST, 'paying'));
$base = trim(filter_input(INPUT_POST, 'base'));
$country = trim(filter_input(INPUT_POST, 'country'));
$gps = trim(filter_input(INPUT_POST, 'gps'));
$query = "INSERT INTO changes (change_id, change_sql_1, change_sql_2, change_sql_3, change_sql_4, change_sql_5, change_note) VALUES (default, 'INSERT INTO owner (owner_id, name, street, city, country) VALUES (default, '$ownername', '$treet', '$city', '$country')', 'INSERT INTO payer (loss_payee_id, loss_payee_name) VALUES (default, '$paying')', '', '', '','')";
I used an echo statement to see what the output looks like, but the SQL statement should contain double quotes ("") around each of the PHP variables. So the PHP variable text will be inside "". Example, if $ownername = 'Jimmy', then the statement being saved should be "Jimmy".