如何从php中的INSERT查询中提取变量?

This is for a registration form I have created. I cannot include all of my code, but the program checks for blank fields then format using the preg_match function. Then it INSERTS the info registered

My code is:

<?php
 /* connection info */
ini_set('include_path','../../includes');
include("dbinfo.inc");
$cxn = mysqli_connect($host,$user,$password,$dbname) 
    or die("Couldn't connect to server. error 3");
?>


<?php
/*  Program name: Register.php 
 *  Description:  Program displays the blank form and checks 
 *  all the form fields for blank fields.
 */


 // Insert info into database //
    {
    foreach($good_data as $field => $value)
        {
            $good_data[$field] = mysqli_real_escape_string($cxn,$value);
        }

    $sql = "INSERT INTO UserInfo (user_id, password, first_name, last_name, city, country, email) VALUES ('$good_data[user_id]', '$good_data[password]', '$good_data[first_name]', '$good_data[last_name]', '$good_data[city]', '$good_data[country]', '$good_data[email]')";

        $result = mysqli_query($query, $sql) or die ("Couldn't connect to login");
        $row = mysqli_fetch($result);

        while ($row = mysql_fetch_assoc($result)) {

            $sql2 = "UPDATE TimeStamp SET time = CURRENT_TIMESTAMP where user_id='$good_data[user_id]'";  
               $result2 = mysqli_query($cxn,$sql2) or die("<p>Couldn't Connect to Login</p>");
                       include('goodReg.inc');

        }
        {
            echo $message;
            extract($good_data);
            include('register.inc');
            exit();
        } 
    }   
}
else
{
  include("register.inc");
}
?>

How do I move just the variable to the query and not the whole INSERT string?

There's no need to call mysqli_fetch or mysqli_fetch_assoc. Just do the UPDATE query outside of a loop:

$sql = "INSERT INTO UserInfo (user_id, password, first_name, last_name, city, country, email) VALUES ('$good_data[user_id]', '$good_data[password]', '$good_data[first_name]', '$good_data[last_name]', '$good_data[city]', '$good_data[country]', '$good_data[email]')";
mysqli_query($cxn, $sql) or die ("Couldn't insert into UserInfo: " . mysqli_error($cxn));

$sql2 = "UPDATE TimeStamp SET time = CURRENT_TIMESTAMP where user_id='$good_data[user_id]'";  
mysqli_query($cxn, $sql2) or die ("Couldn't update TimeStamp: " . mysqli_error($cxn);

include('goodReg.inc');