VAR数据没有推送到SQL

I'm having a slight issue and I'm not sure why. Maybe someone can help me out. First a few disclaimers; I'm still learning PHP, I'm aware of mysqli or pdo but the server this will live on is running an old ver 4 of php.

Ok now on to the problem.

I have a form which passes to my post-data.php form to push to SQL db.

However when it pushes the data it's only pushing the variables not the data within the vars from post action of the form.

Screenshot of submitted data in PHPmyadmin

My Code follows:

<?php
    $hostname = "localhost"; $username = "goldme_owner";
    $dbName = "goldme_dealer_meeting";

    $connect = mysql_connect($hostname, $username);
    if (!$connect) { 
        echo "Please try later."; 
    } 
    else { 
        mysql_select_db($dbName, $connect); 
        $checkboxA1 = isset($_POST['checkboxA1']) ? $_POST['checkboxA1'] : 'No';
        $checkboxE1 = isset($_POST['checkboxE1']) ? $_POST['checkboxE1'] : 'No';
        $checkboxF1 = isset($_POST['checkboxF1']) ? $_POST['checkboxF1'] : 'No';
        $checkboxG1 = isset($_POST['checkboxG1']) ? $_POST['checkboxG1'] : 'No';
        $checkboxH1 = isset($_POST['checkboxH1']) ? $_POST['checkboxH1'] : 'No';
        $checkboxI1 = isset($_POST['checkboxI1']) ? $_POST['checkboxI1'] : 'No';
        $checkboxJ1 = isset($_POST['checkboxJ1']) ? $_POST['checkboxJ1'] : 'No';
        $checkboxK1 = isset($_POST['checkboxK1']) ? $_POST['checkboxK1'] : 'No';
    }

    echo "$checkboxA1"; //just want to make sure checkbox vars are passing //will delete in final code
    echo "$checkboxE1"; //just want to make sure checkbox vars are passing //will delete in final code
    echo "$checkboxF1"; //just want to make sure checkbox vars are passing //will delete in final code
    echo "$checkboxG1"; //just want to make sure checkbox vars are passing //will delete in final code
    echo "$checkboxH1"; //just want to make sure checkbox vars are passing //will delete in final code
    echo "$checkboxI1"; //just want to make sure checkbox vars are passing //will delete in final code
    echo "$checkboxJ1"; //just want to make sure checkbox vars are passing //will delete in final code
    echo "$checkboxK1"; //just want to make sure checkbox vars are passing //will delete in final code
    echo "$_POST[confirm]"; //just want to make sure confirm code generated //will delete in final code

        $sql_statement = 'INSERT INTO 2014_registrations'. 
        '(confirm_number,timecode,company_name,country,address1,address2,city'.
        ',state,zip,phone,fax,email,zone_manager,transport,first_name,'.
        'last_name,tuesday_tours,tuesday_meat,wed_lunch,wed_dinner,'.
        'wed_pool_tourney,thurs_lunch,thurs_dinner,fri_shop,fri_tour,dietary)'.
        'VALUES ("$_POST[confirm]","$_POST[timecode]","$_POST[company_name]",'.
        '"$_POST[address]","$_POST[address2]","$_POST[city]","$_POST[state]",'.
        '"$_POST[zip]","$_POST[country]","$_POST[phone]","$_POST[fax]",'.
        '"$_POST[email]","$_POST[zonemanager]","$_POST[transport]",'.
        '"$_POST[fattendee1]","$_POST[lattendee1]","$_POST[checkboxA1]",'.
        '"$_POST[radio1]","$_POST[checkboxE1]","$_POST[checkboxF1]",'.
        '"$_POST[checkboxG1]","$_POST[checkboxH1]","$_POST[checkboxI1]",'.
        '"$_POST[checkboxJ1]","$_POST[checkboxK1]","$_POST[dietary1]")';


    $rec_insert = mysql_query($sql_statement);
    if(! $rec_insert ){
        die('Could not enter data: ' . mysql_error());
    }
    echo "Entered data successfully
";
    mysql_close($connect);
?> 

Inside single quotes the variables are not read as variables. For example echo '$a' will print $a but echo "$a" will print the value of $a.

In your code you are trying to use something similar to '$a', or in other words you are using single quotes around variables instead of double quotes.

Try writing it as

"VALUES ('$_POST[confirm]','$_POST[timecode]','$_POST[company_name]',".

or

'VALUES ("'.$_POST[confirm].'","'.$_POST[timecode].'","'.$_POST[company_name].'",'.

and so on..

Note that the use of $_POST[confirm] gives an notice. The correct way to use it is $_POST['confirm'].

Also note that your code is vulnerable to SQL injections. Consider using prepared statements.

The variables are being read as strings because they're written in single quotes.

I've moved the variables to outside of the single quotes and just concatenated them to the string. This code is extremely susceptible to SQL injection and should not be used in a production environment.

$sql_statement = 'INSERT INTO 2014_registrations'. 
'(confirm_number,timecode,company_name,country,address1,address2,city'.
',state,zip,phone,fax,email,zone_manager,transport,first_name,'.
'last_name,tuesday_tours,tuesday_meat,wed_lunch,wed_dinner,'.
'wed_pool_tourney,thurs_lunch,thurs_dinner,fri_shop,fri_tour,dietary)'.
'VALUES ("'.$_POST[confirm].'","'.$_POST[timecode].'","'.$_POST[company_name].'",'.
'"'.$_POST[address].'","'.$_POST[address2].'","'.$_POST[city].'","'.$_POST[state].'",'.
'"'.$_POST[zip].'","'.$_POST[country].'","'.$_POST[phone].'","'.$_POST[fax].'",'.
'"'.$_POST[email].'","'.$_POST[zonemanager].'","'.$_POST[transport].'",'.
'"'.$_POST[fattendee1].'","'.$_POST[lattendee1].'","'.$_POST[checkboxA1].'",'.
'"'.$_POST[radio1].'","'.$_POST[checkboxE1].'","'.$_POST[checkboxF1].'",'.
'"'.$_POST[checkboxG1].'","'.$_POST[checkboxH1].'","'.$_POST[checkboxI1].'",'.
'"'.$_POST[checkboxJ1].'","'.$_POST[checkboxK1].'","'.$_POST[dietary1].'")';

First of all, inserting data directly into the db from POST request is almost never a good idea.

I know this is really badly formatted, but try using this $sql_statement instead:

$sql_statement = 'INSERT INTO 2014_registrations'. 
    '(confirm_number,timecode,company_name,country,address1,address2,city'.
    ',state,zip,phone,fax,email,zone_manager,transport,first_name,'.
    'last_name,tuesday_tours,tuesday_meat,wed_lunch,wed_dinner,'.
    'wed_pool_tourney,thurs_lunch,thurs_dinner,fri_shop,fri_tour,dietary)'.
    "VALUES (\"{$_POST[confirm]}\",\"{$_POST[timecode]}\",\"{$_POST[company_name]}\",".
    "\"{$_POST[address]}\",\"{$_POST[address2]}\",\"{$_POST[city]}\",\"{$_POST[state]}\",".
    "\"{$_POST[zip]}\",\"{$_POST[country]}\",\"{$_POST[phone]}\",\"{$_POST[fax]}\",".
    "\"{$_POST[email]}\",\"{$_POST[zonemanager]}\",\"{$_POST[transport]}\",".
    "\"{$_POST[fattendee1]}\",\"{$_POST[lattendee1]}\",\"{$_POST[checkboxA1]}\",".
    "\"{$_POST[radio1]}\",\"{$_POST[checkboxE1]}\",\"{$_POST[checkboxF1]}\",".
    "\"{$_POST[checkboxG1]}\",\"{$_POST[checkboxH1]}\",\"{$_POST[checkboxI1]}\",".
    "\"{$_POST[checkboxJ1]}\",\"{$_POST[checkboxK1]}\",\"{$_POST[dietary1]}\")";

Your `sql_statment is wrong.

$sql_statement = 'INSERT INTO 2014_registrations'. 
    '(confirm_number,timecode,company_name,country,address1,address2,city'.
    ',state,zip,phone,fax,email,zone_manager,transport,first_name,'.
    'last_name,tuesday_tours,tuesday_meat,wed_lunch,wed_dinner,'.
    'wed_pool_tourney,thurs_lunch,thurs_dinner,fri_shop,fri_tour,dietary)'.
    'VALUES ("$_POST[confirm]","$_POST[timecode]","$_POST[company_name]",'.
    '"$_POST[address]","$_POST[address2]","$_POST[city]","$_POST[state]",'.
    '"$_POST[zip]","$_POST[country]","$_POST[phone]","$_POST[fax]",'.
    '"$_POST[email]","$_POST[zonemanager]","$_POST[transport]",'.
    '"$_POST[fattendee1]","$_POST[lattendee1]","$_POST[checkboxA1]",'.
    '"$_POST[radio1]","$_POST[checkboxE1]","$_POST[checkboxF1]",'.
    '"$_POST[checkboxG1]","$_POST[checkboxH1]","$_POST[checkboxI1]",'.
    '"$_POST[checkboxJ1]","$_POST[checkboxK1]","$_POST[dietary1]")';

Change to:

$sql_statment = "INSERT INTO 2014_registrations". 
    "(confirm_number,timecode,company_name,country,address1,address2,city".
    ",state,zip,phone,fax,email,zone_manager,transport,first_name,".
    "last_name,tuesday_tours,tuesday_meat,wed_lunch,wed_dinner,".
    "wed_pool_tourney,thurs_lunch,thurs_dinner,fri_shop,fri_tour,dietary)".
    "VALUES ($_POST['confirm'],$_POST['timecode'],$_POST['company_name'],".
    "$_POST['address'],$_POST['address2'],$_POST['city'],$_POST['state'],".
    "$_POST['zip'],$_POST['country],$_POST[phone'],$_POST['fax'],".
    "$_POST['email'],$_POST['zonemanager'],$_POST['transport'],".
    "$_POST['fattendee1'],$_POST['lattendee1'],$_POST['checkboxA1'],".
    "$_POST['radio1'],$_POST['checkboxE1'],$_POST['checkboxF1'],".
    "$_POST['checkboxG1'],$_POST['checkboxH1'],$_POST['checkboxI1'],".
    "$_POST['checkboxJ1'],$_POST['checkboxK1'],$_POST['dietary1']")";

If you are using $sql_statment = '' you cant put a variable in $sql_statment = '$_POST[confirm]'; because it will treat it like a text. You have to make it like $sql_statment = $_POST['checkboxG1'].','.$_POST['checkboxH1'].','.$_POST['checkboxI1'].','. Another way is to change it all to $sql_statment = "$_POST['checkboxG1'],$_POST['checkboxH1'],$_POST['checkboxI1'],"; like I did.

See that there is a differance in using ' and ";

Btw. you should use some security for example mysql_escape_string.