Jump to content

Nee help with undefined index on line 7


mgmoses

Recommended Posts

Please help.  I do not know why I am getting an undefined index error message on line 7.  I am using EasyPHP 5.3.2i.  :confused:

Line 7 reads "$Total_Purchase = $_POST['Total_Purchase']; $NJ_Tax = $_POST['NJ_Tax']; $SH_Charge = $_POST['SH_Charge']; $Amount_To_Pay = $_POST['Amount_To_Pay']; $CC1 = $_POST['CC1']; $CC2 = $_POST['CC2']; $CC3 = $_POST['CC3']; $CC4 = $_POST['CC4']; $Exp = $_POST['Exp'];"

 

The script is as follows:

<?php

//Define the input  variables
$Name = $_POST['Name']; $Ad1 = $_POST['Ad1']; $Ad2 = $_POST['Ad2']; $City = $_POST['City']; $State = $_POST['State']; $Zip5 = $_POST['Zip5']; $Zip4 = $_POST['Zip4']; $Email = $_POST['Email']; $AreaCode = $_POST['AreaCode']; $Phone3 = $_POST['Phone3']; $Phone4 = $_POST['Phone4']; $Ext = $_POST['Ext'];
$Item01Qty = $_POST['Item01Qty']; $Item02Qty = $_POST['Item02Qty']; $Item03Qty = $_POST['Item03Qty']; $Item04Qty = $_POST['Item04Qty']; $Item05Qty = $_POST['Item05Qty']; $Item06Qty = $_POST['Item06Qty']; $Item07Qty = $_POST['Item07Qty'];
$Item01Total = $_POST['Item01Total']; $Item02Total = $_POST['Item02Total']; $Item03Total = $_POST['Item03Total']; $Item04Total = $_POST['Item04Total']; $Item05Total = $_POST['Item05Total']; $Item06Total = $_POST['Item06Total']; $Item07Total = $_POST['Item07Total'];
$Total_Purchase = $_POST['Total_Purchase']; $NJ_Tax = $_POST['NJ_Tax']; $SH_Charge = $_POST['SH_Charge']; $Amount_To_Pay = $_POST['Amount_To_Pay']; $CC1 = $_POST['CC1']; $CC2 = $_POST['CC2']; $CC3 = $_POST['CC3']; $CC4 = $_POST['CC4']; $Exp = $_POST['Exp'];


//uncomment for debugging
//print_r($_POST);

//most sites have magic quotes on
//but if they do not, this code simulates magic quotes
if( !get_magic_quotes_gpc() )
{
    if( is_array($_POST) )
        $_POST = array_map('addslashes', $_POST);
}
$error = array();

//make sure there is data in the name and email fields
if( empty($_POST["Name"]) )
{
    $error["Name"] = "Your Name is required.";
    $Name = "";
}
else
    $Name = $_POST["Name"];

if( empty($_POST["Email"]) )
{
    $error["email"] = "Please include your Email address.";
    $Email = "";
}
else
    $Email = $_POST["Email"];

//we need to make sure the order total was calculated before using the submit button
if( empty($_POST["Amount_To_Pay"]) )
    $error["no_qty"] = "Please go back and calculate your order total and resubmit.";


//we should have at least 1 item ordered in the form
if( empty($_POST["Item01Qty"]) && empty($_POST["Item02Qty"]) && empty($_POST["Item03Qty"]) && empty($_POST["Item04Qty"]) && empty($_POST["Item05Qty"]) && empty($_POST["Item06Qty"]) && empty($_POST["Item07Qty"]) )
    $error["no_qty"] = "Please enter at least 1 item to order.";

if(count($error) )
{ 

    echo "An error occurred while processing your order.";
    echo "<br>\n";
    echo "Please check the following error messages carefully, then click back in your browser and make corrections.";
    echo "<br>\n";

    while(list($key, $val) = each($error))
    {
        echo $val;
        echo "<br>\n";
    }

    //stop everything as we have errors and should not continue
    exit();

}


//we can store the order in a database as well

$link = @mysql_connect('localhost', 'Bruce', 'heatwave914');
if (!$link)
{
   echo "Could not connect: " . mysql_error();
}
else
{
    mysql_select_db('orders');

    $query  = "INSERT INTO orders
             ('Number', 'Name', 'Ad1', 'Ad2', 'City', 'State', 'Zip5', 'Zip4', 'Email', 'AreaCode', 'Phone3', 'Phone4', 'Ext',
                'Item01Qty', 'Item02Qty', 'Item03Qty',  'Item04Qty', 'Item05Qty',  'Item06Qty',  'Item07Qty',
'Item01Total', 'Item02Total', 'Item03Total', 'Item04Total', 'Item05Total', 'Item06Total', 'Item07Total',
'Total_Purchase', 'NJ_Tax', 'SH_Charge', 'Amount_To_Pay', 'CC1', 'CC2', 'CC3', 'CC4', 'Exp' )";
    $query .= " VALUES
             ('', '$Name', '$Ad1', '$Ad2', '$City', '$State', '$Zip5', '$Zip4', '$Email', '$AreaCode', '$Phone3', '$Phone4', '$Ext',
                 'Item01Qty', 'Item02Qty', 'Item03Qty',  'Item04Qty', 'Item05Qty',  'Item06Qty',  'Item07Qty',
'Item01Total', 'Item02Total', 'Item03Total', 'Item04Total', 'Item05Total', 'Item06Total', 'Item07Total',
'Total_Purchase', 'NJ_Tax', 'SH_Charge', 'Amount_To_Pay', 'CC1', 'CC2', 'CC3', 'CC4', 'Exp' )";

//echo $query . "<br>\n";    
    $result = mysql_query($query);
       mysql_close($link);
}
?>

 

Also, my data is not posting to my database.  Would appreciate your thoughts on that as well.  Thanks a million in advance for your help!

Link to comment
Share on other sites

:D Thanks Matthew!  One of my variables was misspelled.  That got rid of the undefined index.  However,  my data still does not post to my database.  :confused:  After the script runs, the browser goes blank and just hangs.  My database is called Orders, using TableA.  The variables listed in the database are in the same order as listed in the php file.  Again, below is the script:
<?php

//Define the input  variables
$Name = $_POST['Name']; $Ad1 = $_POST['Ad1']; $Ad2 = $_POST['Ad2']; $City = $_POST['City']; $State = $_POST['State']; $Zip5 = $_POST['Zip5']; $Zip4 = $_POST['Zip4']; $Email = $_POST['Email']; $AreaCode = $_POST['AreaCode']; $Phone3 = $_POST['Phone3']; $Phone4 = $_POST['Phone4']; $Ext = $_POST['Ext'];
$Item01Qty = $_POST['Item01Qty']; $Item02Qty = $_POST['Item02Qty']; $Item03Qty = $_POST['Item03Qty']; $Item04Qty = $_POST['Item04Qty']; $Item05Qty = $_POST['Item05Qty']; $Item06Qty = $_POST['Item06Qty']; $Item07Qty = $_POST['Item07Qty'];
$Item01Total = $_POST['Item01Total']; $Item02Total = $_POST['Item02Total']; $Item03Total = $_POST['Item03Total']; $Item04Total = $_POST['Item04Total']; $Item05Total = $_POST['Item05Total']; $Item06Total = $_POST['Item06Total']; $Item07Total = $_POST['Item07Total'];
$Total_Purchase = $_POST['Total_Purchase']; $NJ_Tax = $_POST['NJ_Tax']; $SH_Charge = $_POST['SH_Charge']; $Amount_To_Pay = $_POST['Amount_To_Pay']; $CC1 = $_POST['CC1']; $CC2 = $_POST['CC2']; $CC3 = $_POST['CC3']; $CC4 = $_POST['CC4']; $Expires = $_POST['Expires'];


//uncomment for debugging
//print_r($_POST);

//most sites have magic quotes on
//but if they do not, this code simulates magic quotes
if( !get_magic_quotes_gpc() )
{
    if( is_array($_POST) )
        $_POST = array_map('addslashes', $_POST);
}
$error = array();

//make sure there is data in the name and email fields
if( empty($_POST["Name"]) )
{
    $error["Name"] = "Your Name is required.";
    $Name = "";
}
else
    $Name = $_POST["Name"];

if( empty($_POST["Email"]) )
{
    $error["email"] = "Please include your Email address.";
    $Email = "";
}
else
    $Email = $_POST["Email"];

//we need to make sure the order total was calculated before using the submit button
if( empty($_POST["Amount_To_Pay"]) )
    $error["no_qty"] = "Please go back and calculate your order total and resubmit.";


//we should have at least 1 item ordered in the form
if( empty($_POST["Item01Qty"]) && empty($_POST["Item02Qty"]) && empty($_POST["Item03Qty"]) && empty($_POST["Item04Qty"]) && empty($_POST["Item05Qty"]) && empty($_POST["Item06Qty"]) && empty($_POST["Item07Qty"]) )
    $error["no_qty"] = "Please enter at least 1 item to order.";

if(count($error) )
{ 

    echo "An error occurred while processing your order.";
    echo "<br>\n";
    echo "Please check the following error messages carefully, then click back in your browser and make corrections.";
    echo "<br>\n";

    while(list($key, $val) = each($error))
    {
        echo $val;
        echo "<br>\n";
    }

    //stop everything as we have errors and should not continue
    exit();

}


//we can store the order in a database as well

$link = @mysql_connect('localhost', 'Bruce', 'heatwave914');
if (!$link)
{
   echo "Could not connect: " . mysql_error();
}
else
{
    mysql_select_db('orders');

    $query  = "INSERT INTO orders
             ('Number', 'Name', 'Ad1', 'Ad2', 'City', 'State', 'Zip5', 'Zip4', 'Email', 'AreaCode', 'Phone3', 'Phone4', 'Ext',
                'Item01Qty', 'Item02Qty', 'Item03Qty',  'Item04Qty', 'Item05Qty',  'Item06Qty',  'Item07Qty',
'Item01Total', 'Item02Total', 'Item03Total', 'Item04Total', 'Item05Total', 'Item06Total', 'Item07Total',
'Total_Purchase', 'NJ_Tax', 'SH_Charge', 'Amount_To_Pay', 'CC1', 'CC2', 'CC3', 'CC4', 'Expires' )";
    $query .= " VALUES
             ('', '$Name', '$Ad1', '$Ad2', '$City', '$State', '$Zip5', '$Zip4', '$Email', '$AreaCode', '$Phone3', '$Phone4', '$Ext',
                 'Item01Qty', 'Item02Qty', 'Item03Qty',  'Item04Qty', 'Item05Qty',  'Item06Qty',  'Item07Qty',
'Item01Total', 'Item02Total', 'Item03Total', 'Item04Total', 'Item05Total', 'Item06Total', 'Item07Total',
'Total_Purchase', 'NJ_Tax', 'SH_Charge', 'Amount_To_Pay', 'CC1', 'CC2', 'CC3', 'CC4', 'Expires' )";

//echo $query . "<br>\n";    
    $result = mysql_query($query);
       mysql_close($link);
}
?>

  Thanks again for your help and assistance.  I think I'm almost there!

Link to comment
Share on other sites

Why are you putting multiple statements on each line. That makes debugging extremely hard.

 

That top section makes no sense anyway. Just use the values in the $_POST array.

 

I took you code and modified it quite a bit. See if this works

<?php
if( get_magic_quotes_gpc() )
{
    if( is_array($_POST) )
        $_POST = array_map('stripslashes', $_POST);
}
$error = array();
$qtmp = array();
foreach ($_POST as $k=>$v) {
switch ($k) {
	case 'Name':
		if (strlen(trim($v)) == 0) {
			$error[] = 'Your Name is required';
		} else {
			$qtmp[] = $k . " = '" . mysql_real_escape_string($v) . "'";
		}
		break;
	case 'Email':
		if (strlen(trim($v)) == 0) {
			$error[] = 'Please include your Email address.';
		} else {
			$qtmp[] = $k . " = '" . mysql_real_escape_string($v) . "'";
		}
		break;
	case 'Amount_To_Pay':
		if (strlen(trim($v)) == 0) {
			$error[] = 'Please go back and calculate your order total and resubmit.';
		} else {
			$qtmp[] = $k . " = '" . mysql_real_escape_string($v) . "'";
		}
		break;
	case 'Item01Qty':
	case 'Item02Qty':
	case 'Item03Qty':
	case 'Item04Qty':
	case 'Item05Qty':
	case 'Item06Qty':
	case 'Item07Qty':
			break;
		default:
			$qtmp[] = $k . " = '" . mysql_real_escape_string($v) . "'";
	}
}
$no_items_filled = 0
for($i=1;$i<8;++$i) {
	if (strlen(trim($_POST['Item0' . $i . 'Qty'])) == 0) {
		$no_items_filled++;
	} else {
		$qtmp[] = 'Item0' . $i . "Qty = '" . mysql_real_escape_string($_POST['Item0' . $i . 'Qty'] . "'";
	}
}
if ($no_items_filed == 7) {
$error[] = 'Please enter at least 1 item to order.';
}
if(!empty($error))
{ 

    echo "An error occurred while processing your order.";
    echo "<br>\n";
    echo "Please check the following error messages carefully, then click back in your browser and make corrections.";
    echo "<br>\n";
    echo implode("<br>\n", $error) . "<br>\n";
} else {


//we can store the order in a database as well

$link = mysql_connect('localhost', 'Bruce', 'heatwave914') or die('Could not connect');
mysql_select_db('orders') or die('Could not select database <br>' . mysql_error());
$query = 'insert into orders set ' . implode(', ', $qtmp);
  $result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());
}
?>

 

Note: not checked for syntax errors.

 

Ken

Link to comment
Share on other sites

Thanks Ken.  However I am new to php and I really don't want to revamp so much script.  I did make some minor changes myself and I am able to determine that the script is working but the data is not getting posted to the database.  :confused:  I was able to echo the query and it is picking up what I input into the html form.  The data is just not going into the database!  :'(  My database is called "orders" and the table is now called "capture."  Here is the script that I am using now:

<?php

//Define the input  variables
$Name = $_POST['Name']; $Ad1 = $_POST['Ad1']; $Ad2 = $_POST['Ad2']; $City = $_POST['City']; $State = $_POST['State']; $Zip5 = $_POST['Zip5']; $Zip4 = $_POST['Zip4']; $Email = $_POST['Email']; $AreaCode = $_POST['AreaCode']; $Phone3 = $_POST['Phone3']; $Phone4 = $_POST['Phone4']; $Ext = $_POST['Ext'];
$Item01Qty = $_POST['Item01Qty']; $Item02Qty = $_POST['Item02Qty']; $Item03Qty = $_POST['Item03Qty']; $Item04Qty = $_POST['Item04Qty']; $Item05Qty = $_POST['Item05Qty']; $Item06Qty = $_POST['Item06Qty']; $Item07Qty = $_POST['Item07Qty'];
$Item01Total = $_POST['Item01Total']; $Item02Total = $_POST['Item02Total']; $Item03Total = $_POST['Item03Total']; $Item04Total = $_POST['Item04Total']; $Item05Total = $_POST['Item05Total']; $Item06Total = $_POST['Item06Total']; $Item07Total = $_POST['Item07Total'];
$Total_Purchase = $_POST['Total_Purchase']; $NJ_Tax = $_POST['NJ_Tax']; $SH_Charge = $_POST['SH_Charge']; $Amount_To_Pay = $_POST['Amount_To_Pay']; $CC1 = $_POST['CC1']; $CC2 = $_POST['CC2']; $CC3 = $_POST['CC3']; $CC4 = $_POST['CC4']; $Expires = $_POST['Expires'];


//uncomment for debugging
//print_r($_POST);

//most sites have magic quotes on
//but if they do not, this code simulates magic quotes
if( !get_magic_quotes_gpc() )
{
    if( is_array($_POST) )
        $_POST = array_map('addslashes', $_POST);
}
$error = array();

//make sure there is data in the name and email fields
if( empty($_POST["Name"]) )
{
    $error["Name"] = "Your Name is required.";
    $Name = "";
}
else
    $Name = $_POST["Name"];

if( empty($_POST["Email"]) )
{
    $error["email"] = "Please include your Email address.";
    $Email = "";
}
else
    $Email = $_POST["Email"];

//we need to make sure the order total was calculated before using the submit button
if( empty($_POST["Amount_To_Pay"]) )
    $error["no_qty"] = "Please go back and calculate your order total and resubmit.";


//we should have at least 1 item ordered in the form
if( empty($_POST["Item01Qty"]) && empty($_POST["Item02Qty"]) && empty($_POST["Item03Qty"]) && empty($_POST["Item04Qty"]) && empty($_POST["Item05Qty"]) && empty($_POST["Item06Qty"]) && empty($_POST["Item07Qty"]) )
    $error["no_qty"] = "Please enter at least 1 item to order.";

if(count($error) )
{ 

    echo "An error occurred while processing your order.";
    echo "<br>\n";
    echo "Please check the following error messages carefully, then click back in your browser and make corrections.";
    echo "<br>\n";

    while(list($key, $val) = each($error))
    {
        echo $val;
        echo "<br>\n";
    }

    //stop everything as we have errors and should not continue
    exit();

}


//we can store the order in a database as well

$conn = mysql_connect ('127.0.0.1', 'Bruce', 'heatwave914') or die  ('Could not connect');
mysql_select_db ('orders');

    $query  = "INSERT INTO capture VALUES
                  (' ', '$Name', '$Ad1', '$Ad2', '$City', '$State', '$Zip5', '$Zip4', '$Email', '$AreaCode', '$Phone3', '$Phone4', '$Ext',
                 '$Item01Qty', '$Item02Qty', '$Item03Qty',  '$Item04Qty', '$Item05Qty',  '$Item06Qty',  '$Item07Qty',
'$Item01Total', '$Item02Total', '$Item03Total', '$Item04Total', '$Item05Total', '$Item06Total', '$Item07Total',
'$Total_Purchase', '$NJ_Tax', '$SH_Charge', '$Amount_To_Pay', '$CC1', '$CC2', '$CC3', '$CC4', '$Expires' )";

echo $query;

           mysql_close($conn);

?>

  Please give me your thoughts and suggestions as I am going to be bald soon after pulling out all my hair!  :shrug:

Link to comment
Share on other sites

It is not inserting the values because it doesn't know where to put them.

 

$query  = "INSERT INTO capture VALUES
                  (' ', '$Name', '$Ad1', '$Ad2', '$City', '$State', '$Zip5', '$Zip4', '$Email', '$AreaCode', '$Phone3', '$Phone4', '$Ext',
                 '$Item01Qty', '$Item02Qty', '$Item03Qty',  '$Item04Qty', '$Item05Qty',  '$Item06Qty',  '$Item07Qty',



'$Item01Total', '$Item02Total', '$Item03Total', '$Item04Total', '$Item05Total', '$Item06Total', '$Item07Total',



'$Total_Purchase', '$NJ_Tax', '$SH_Charge', '$Amount_To_Pay', '$CC1', '$CC2', '$CC3', '$CC4', '$Expires' )";

 

I believe the proper syntax for this would be

$query  = "INSERT INTO tablename (columns) VALUES (data)";

 

If your first column is auto incrementing, then I suggest you just skip to Name in the columns section and do the same for the values. Putting the ' ' in the values is a bad idea.

 

In your case it would look like

$query = "INSERT INTO capture ('Name', 'Ad1', 'Ad2', . . .) VALUES ('$Name', '$Ad1', '$Ad2', . . .)";

Link to comment
Share on other sites

Richard...Parts of your comments are cut off.  However I think I got the jist of what you were thinking.  Below is my code incorporating your comments, as I believe them to be.  However,  :'(  it still does not post any data to the database!?

<?php

//Define the input  variables
$Name = $_POST['Name']; $Ad1 = $_POST['Ad1']; $Ad2 = $_POST['Ad2']; $City = $_POST['City']; $State = $_POST['State']; $Zip5 = $_POST['Zip5']; $Zip4 = $_POST['Zip4']; $Email = $_POST['Email']; $AreaCode = $_POST['AreaCode']; $Phone3 = $_POST['Phone3']; $Phone4 = $_POST['Phone4']; $Ext = $_POST['Ext'];
$Item01Qty = $_POST['Item01Qty']; $Item02Qty = $_POST['Item02Qty']; $Item03Qty = $_POST['Item03Qty']; $Item04Qty = $_POST['Item04Qty']; $Item05Qty = $_POST['Item05Qty']; $Item06Qty = $_POST['Item06Qty']; $Item07Qty = $_POST['Item07Qty'];
$Item01Total = $_POST['Item01Total']; $Item02Total = $_POST['Item02Total']; $Item03Total = $_POST['Item03Total']; $Item04Total = $_POST['Item04Total']; $Item05Total = $_POST['Item05Total']; $Item06Total = $_POST['Item06Total']; $Item07Total = $_POST['Item07Total'];
$Total_Purchase = $_POST['Total_Purchase']; $NJ_Tax = $_POST['NJ_Tax']; $SH_Charge = $_POST['SH_Charge']; $Amount_To_Pay = $_POST['Amount_To_Pay']; $CC1 = $_POST['CC1']; $CC2 = $_POST['CC2']; $CC3 = $_POST['CC3']; $CC4 = $_POST['CC4']; $Expires = $_POST['Expires'];


//uncomment for debugging
//print_r($_POST);

//most sites have magic quotes on
//but if they do not, this code simulates magic quotes
if( !get_magic_quotes_gpc() )
{
    if( is_array($_POST) )
        $_POST = array_map('addslashes', $_POST);
}
$error = array();

//make sure there is data in the name and email fields
if( empty($_POST["Name"]) )
{
    $error["Name"] = "Your Name is required.";
    $Name = "";
}
else
    $Name = $_POST["Name"];

if( empty($_POST["Email"]) )
{
    $error["email"] = "Please include your Email address.";
    $Email = "";
}
else
    $Email = $_POST["Email"];

//we need to make sure the order total was calculated before using the submit button
if( empty($_POST["Amount_To_Pay"]) )
    $error["no_qty"] = "Please go back and calculate your order total and resubmit.";


//we should have at least 1 item ordered in the form
if( empty($_POST["Item01Qty"]) && empty($_POST["Item02Qty"]) && empty($_POST["Item03Qty"]) && empty($_POST["Item04Qty"]) && empty($_POST["Item05Qty"]) && empty($_POST["Item06Qty"]) && empty($_POST["Item07Qty"]) )
    $error["no_qty"] = "Please enter at least 1 item to order.";

if(count($error) )
{ 

    echo "An error occurred while processing your order.";
    echo "<br>\n";
    echo "Please check the following error messages carefully, then click back in your browser and make corrections.";
    echo "<br>\n";

    while(list($key, $val) = each($error))
    {
        echo $val;
        echo "<br>\n";
    }

    //stop everything as we have errors and should not continue
    exit();

}


//we can store the order in a database as well

$conn = mysql_connect ('127.0.0.1', 'Bruce', 'heatwave914') or die  ('Could not connect');
mysql_select_db ('orders');

    $query  = "INSERT INTO capture
                  ('$Name', '$Ad1', '$Ad2', '$City', '$State', '$Zip5', '$Zip4', '$Email', '$AreaCode', '$Phone3', '$Phone4', '$Ext',
                 '$Item01Qty', '$Item02Qty', '$Item03Qty',  '$Item04Qty', '$Item05Qty',  '$Item06Qty',  '$Item07Qty',
'$Item01Total', '$Item02Total', '$Item03Total', '$Item04Total', '$Item05Total', '$Item06Total', '$Item07Total',
'$Total_Purchase', '$NJ_Tax', '$SH_Charge', '$Amount_To_Pay', '$CC1', '$CC2', '$CC3', '$CC4', '$Expires' )
VALUES ('$Name', '$Ad1', '$Ad2', '$City', '$State', '$Zip5', '$Zip4', '$Email', '$AreaCode', '$Phone3', '$Phone4', '$Ext',
'$Item01Qty', '$Item02Qty', '$Item03Qty',  '$Item04Qty', '$Item05Qty',  '$Item06Qty',  '$Item07Qty',
'$Item01Total', '$Item02Total', '$Item03Total', '$Item04Total', '$Item05Total', '$Item06Total', '$Item07Total',
'$Total_Purchase', '$NJ_Tax', '$SH_Charge', '$Amount_To_Pay', '$CC1', '$CC2', '$CC3', '$CC4', '$Expires' )";

echo "database updated";

           mysql_close($conn);

?>

  Any more help would be greatly appreciated!!!  :shrug:

Link to comment
Share on other sites

Do you see the problem you are creating with this code here?

$query  = "INSERT INTO capture
('$Name', '$Ad1', '$Ad2', '$City', '$State', '$Zip5', '$Zip4', '$Email', '$AreaCode', '$Phone3', '$Phone4', '$Ext',
'$Item01Qty', '$Item02Qty', '$Item03Qty',  '$Item04Qty', '$Item05Qty',  '$Item06Qty',  '$Item07Qty',	'$Item01Total',
'$Item02Total', '$Item03Total', '$Item04Total', '$Item05Total', '$Item06Total', '$Item07Total','$Total_Purchase', 
'$NJ_Tax', '$SH_Charge', '$Amount_To_Pay', '$CC1', '$CC2', '$CC3', '$CC4', '$Expires' )
VALUES ('$Name', '$Ad1', '$Ad2', '$City', '$State', '$Zip5', '$Zip4', '$Email', '$AreaCode', '$Phone3', '$Phone4', '$Ext',
'$Item01Qty', '$Item02Qty', '$Item03Qty',  '$Item04Qty', '$Item05Qty',  '$Item06Qty',  '$Item07Qty',
'$Item01Total', '$Item02Total', '$Item03Total', '$Item04Total', '$Item05Total', '$Item06Total', '$Item07Total',
'$Total_Purchase', '$NJ_Tax', '$SH_Charge', '$Amount_To_Pay', '$CC1', '$CC2', '$CC3', '$CC4', '$Expires' )";

 

I doubt that the fields that you are trying to put data in are named with the data that the user sends. Take a look and try again.

Link to comment
Share on other sites

Richard.....Okay I think I see what you're saying ----I removed the "$" in front of the column names.  Here is the new code:

<?php

//Define the input  variables
$Name = $_POST['Name']; $Ad1 = $_POST['Ad1']; $Ad2 = $_POST['Ad2']; $City = $_POST['City']; $State = $_POST['State']; $Zip5 = $_POST['Zip5']; $Zip4 = $_POST['Zip4']; $Email = $_POST['Email']; $AreaCode = $_POST['AreaCode']; $Phone3 = $_POST['Phone3']; $Phone4 = $_POST['Phone4']; $Ext = $_POST['Ext'];
$Item01Qty = $_POST['Item01Qty']; $Item02Qty = $_POST['Item02Qty']; $Item03Qty = $_POST['Item03Qty']; $Item04Qty = $_POST['Item04Qty']; $Item05Qty = $_POST['Item05Qty']; $Item06Qty = $_POST['Item06Qty']; $Item07Qty = $_POST['Item07Qty'];
$Item01Total = $_POST['Item01Total']; $Item02Total = $_POST['Item02Total']; $Item03Total = $_POST['Item03Total']; $Item04Total = $_POST['Item04Total']; $Item05Total = $_POST['Item05Total']; $Item06Total = $_POST['Item06Total']; $Item07Total = $_POST['Item07Total'];
$Total_Purchase = $_POST['Total_Purchase']; $NJ_Tax = $_POST['NJ_Tax']; $SH_Charge = $_POST['SH_Charge']; $Amount_To_Pay = $_POST['Amount_To_Pay']; $CC1 = $_POST['CC1']; $CC2 = $_POST['CC2']; $CC3 = $_POST['CC3']; $CC4 = $_POST['CC4']; $Expires = $_POST['Expires'];


//uncomment for debugging
//print_r($_POST);

//most sites have magic quotes on
//but if they do not, this code simulates magic quotes
if( !get_magic_quotes_gpc() )
{
    if( is_array($_POST) )
        $_POST = array_map('addslashes', $_POST);
}
$error = array();

//make sure there is data in the name and email fields
if( empty($_POST["Name"]) )
{
    $error["Name"] = "Your Name is required.";
    $Name = "";
}
else
    $Name = $_POST["Name"];

if( empty($_POST["Email"]) )
{
    $error["email"] = "Please include your Email address.";
    $Email = "";
}
else
    $Email = $_POST["Email"];

//we need to make sure the order total was calculated before using the submit button
if( empty($_POST["Amount_To_Pay"]) )
    $error["no_qty"] = "Please go back and calculate your order total and resubmit.";


//we should have at least 1 item ordered in the form
if( empty($_POST["Item01Qty"]) && empty($_POST["Item02Qty"]) && empty($_POST["Item03Qty"]) && empty($_POST["Item04Qty"]) && empty($_POST["Item05Qty"]) && empty($_POST["Item06Qty"]) && empty($_POST["Item07Qty"]) )
    $error["no_qty"] = "Please enter at least 1 item to order.";

if(count($error) )
{ 

    echo "An error occurred while processing your order.";
    echo "<br>\n";
    echo "Please check the following error messages carefully, then click back in your browser and make corrections.";
    echo "<br>\n";

    while(list($key, $val) = each($error))
    {
        echo $val;
        echo "<br>\n";
    }

    //stop everything as we have errors and should not continue
    exit();

}


//we can store the order in a database as well

$conn = mysql_connect ('127.0.0.1', 'Bruce', 'heatwave914') or die  ('Could not connect');
mysql_select_db ('orders');

    $query  = "INSERT INTO capture
                  ('Name', 'Ad1', 'Ad2', 'City', 'State', 'Zip5', 'Zip4', 'Email', 'AreaCode', 'Phone3', 'Phone4', 'Ext',
                 'Item01Qty', 'Item02Qty', 'Item03Qty',  'Item04Qty', 'Item05Qty',  'Item06Qty',  'Item07Qty',
'Item01Total', 'Item02Total', 'Item03Total', 'Item04Total', 'Item05Total', 'Item06Total', 'Item07Total',
'Total_Purchase', 'NJ_Tax', 'SH_Charge', 'Amount_To_Pay', 'CC1', 'CC2', 'CC3', 'CC4', 'Expires' )
VALUES ('$Name', '$Ad1', '$Ad2', '$City', '$State', '$Zip5', '$Zip4', '$Email', '$AreaCode', '$Phone3', '$Phone4', '$Ext',
'$Item01Qty', '$Item02Qty', '$Item03Qty',  '$Item04Qty', '$Item05Qty',  '$Item06Qty',  '$Item07Qty',
'$Item01Total', '$Item02Total', '$Item03Total', '$Item04Total', '$Item05Total', '$Item06Total', '$Item07Total',
'$Total_Purchase', '$NJ_Tax', '$SH_Charge', '$Amount_To_Pay', '$CC1', '$CC2', '$CC3', '$CC4', '$Expires' )";

echo "database updated";

           mysql_close($conn);

?>

  However, it still is not working!  Here is the structure of my database in case you find it useful

 127.0.0.1   orders   capture 
Browse
Structure
SQL
Search
Tracking
Insert
Export
Import
Operations
Empty
Drop
  Field Type Collation Attributes Null Default Extra Action 
  Number int(7)   No None auto_increment               
  Name varchar(30) latin1_general_ci  No None                
  Ad1 varchar(30) latin1_general_ci  No None                
  Ad2 varchar(30) latin1_general_ci  No None                
  City varchar(30) latin1_general_ci  No None                
  State varchar(2) latin1_general_ci  No None                
  Zip5 varchar(5) latin1_general_ci  No None                
  Zip4 varchar(4) latin1_general_ci  No None                
  Email varchar(30) latin1_general_ci  No None                
  AreaCode varchar(3) latin1_general_ci  No None                
  Phone3 varchar(3) latin1_general_ci  No None                
  Phone4 varchar(4) latin1_general_ci  No None                
  Ext varchar(10) latin1_general_ci  No None                
  Item01Qty varchar(3) latin1_general_ci  No None                
  Item02Qty varchar(3) latin1_general_ci  No None                
  Item03Qty varchar(3) latin1_general_ci  No None                
  Item04Qty varchar(3) latin1_general_ci  No None                
  Item05Qty varchar(3) latin1_general_ci  No None                
  Item06Qty varchar(3) latin1_general_ci  No None                
  Item07Qty varchar(3) latin1_general_ci  No None                
  Item01Total varchar(10) latin1_general_ci  No None                
  Item02Total varchar(10) latin1_general_ci  No None                
  Item03Total varchar(10) latin1_general_ci  No None                
  Item04Total varchar(10) latin1_general_ci  No None                
  Item05Total varchar(10) latin1_general_ci  No None                
  Item06Total varchar(10) latin1_general_ci  No None                
  Item07Total varchar(10) latin1_general_ci  No None                
  Total_Purchase varchar(10) latin1_general_ci  No None                
  NJ_Tax varchar(10) latin1_general_ci  No None                
  SH_Charge varchar(10) latin1_general_ci  No None                
  Amount_To_Pay varchar(10) latin1_general_ci  No None                
  CC1 varchar(4) latin1_general_ci  No None                
  CC2 varchar(4) latin1_general_ci  No None                
  CC3 varchar(4) latin1_general_ci  No None                
  CC4 varchar(4) latin1_general_ci  No None                
  Expires varchar(5) latin1_general_ci  No None                
Check All / Uncheck All With selected:        
--------------------------------------------------------------------------------
Print view Relation view Propose table structure  Track table 
Add  field(s) At End of Table  At Beginning of Table  After Number Name Ad1 Ad2 City State Zip5 Zip4 Email AreaCode Phone3 Phone4 Ext Item01Qty Item02Qty Item03Qty Item04Qty Item05Qty Item06Qty Item07Qty Item01Total Item02Total Item03Total Item04Total Item05Total Item06Total Item07Total Total_Purchase NJ_Tax SH_Charge Amount_To_Pay CC1 CC2 CC3 CC4 Expires 
--------------------------------------------------------------------------------

Browse
Structure
SQL
Search
Tracking
Insert
Export
Import
Operations
Empty
Drop
Indexes: 
Action Keyname Type Unique Packed Field Cardinality Collation Null Comment 
  PRIMARY BTREE Yes No Number 0 A   

Create an index on  columns   
+ Details...Space usage Type Usage 
Data 0 B 
Index 1,024 B 
Total 1,024 B 
Row Statistics Statements Value 
Format dynamic 
Collation latin1_swedish_ci 
Rows 0 
Next Autoindex 2 
Creation Jun 09, 2010 at 12:52 PM 
Last update Jun 09, 2010 at 12:52 PM 

  What do I do now?  Please help. :'(

Link to comment
Share on other sites

Thomas,  I added the change to the script that you indicated.  Here is the script now:

<?php

//Define the input  variables
$Name = $_POST['Name']; $Ad1 = $_POST['Ad1']; $Ad2 = $_POST['Ad2']; $City = $_POST['City']; $State = $_POST['State']; $Zip5 = $_POST['Zip5']; $Zip4 = $_POST['Zip4']; $Email = $_POST['Email']; $AreaCode = $_POST['AreaCode']; $Phone3 = $_POST['Phone3']; $Phone4 = $_POST['Phone4']; $Ext = $_POST['Ext'];
$Item01Qty = $_POST['Item01Qty']; $Item02Qty = $_POST['Item02Qty']; $Item03Qty = $_POST['Item03Qty']; $Item04Qty = $_POST['Item04Qty']; $Item05Qty = $_POST['Item05Qty']; $Item06Qty = $_POST['Item06Qty']; $Item07Qty = $_POST['Item07Qty'];
$Item01Total = $_POST['Item01Total']; $Item02Total = $_POST['Item02Total']; $Item03Total = $_POST['Item03Total']; $Item04Total = $_POST['Item04Total']; $Item05Total = $_POST['Item05Total']; $Item06Total = $_POST['Item06Total']; $Item07Total = $_POST['Item07Total'];
$Total_Purchase = $_POST['Total_Purchase']; $NJ_Tax = $_POST['NJ_Tax']; $SH_Charge = $_POST['SH_Charge']; $Amount_To_Pay = $_POST['Amount_To_Pay']; $CC1 = $_POST['CC1']; $CC2 = $_POST['CC2']; $CC3 = $_POST['CC3']; $CC4 = $_POST['CC4']; $Expires = $_POST['Expires'];


//uncomment for debugging
//print_r($_POST);

//most sites have magic quotes on
//but if they do not, this code simulates magic quotes
if( !get_magic_quotes_gpc() )
{
    if( is_array($_POST) )
        $_POST = array_map('addslashes', $_POST);
}
$error = array();

//make sure there is data in the name and email fields
if( empty($_POST["Name"]) )
{
    $error["Name"] = "Your Name is required.";
    $Name = "";
}
else
    $Name = $_POST["Name"];

if( empty($_POST["Email"]) )
{
    $error["email"] = "Please include your Email address.";
    $Email = "";
}
else
    $Email = $_POST["Email"];

//we need to make sure the order total was calculated before using the submit button
if( empty($_POST["Amount_To_Pay"]) )
    $error["no_qty"] = "Please go back and calculate your order total and resubmit.";


//we should have at least 1 item ordered in the form
if( empty($_POST["Item01Qty"]) && empty($_POST["Item02Qty"]) && empty($_POST["Item03Qty"]) && empty($_POST["Item04Qty"]) && empty($_POST["Item05Qty"]) && empty($_POST["Item06Qty"]) && empty($_POST["Item07Qty"]) )
    $error["no_qty"] = "Please enter at least 1 item to order.";

if(count($error) )
{ 

    echo "An error occurred while processing your order.";
    echo "<br>\n";
    echo "Please check the following error messages carefully, then click back in your browser and make corrections.";
    echo "<br>\n";

    while(list($key, $val) = each($error))
    {
        echo $val;
        echo "<br>\n";
    }

    //stop everything as we have errors and should not continue
    exit();

}


//we can store the order in a database as well

$conn = mysql_connect ('127.0.0.1', 'Bruce', 'heatwave914') or die  ('Could not connect');
mysql_select_db ('orders');

    $query  = "INSERT INTO capture
                  ('Name', 'Ad1', 'Ad2', 'City', 'State', 'Zip5', 'Zip4', 'Email', 'AreaCode', 'Phone3', 'Phone4', 'Ext',
                 'Item01Qty', 'Item02Qty', 'Item03Qty',  'Item04Qty', 'Item05Qty',  'Item06Qty',  'Item07Qty',
'Item01Total', 'Item02Total', 'Item03Total', 'Item04Total', 'Item05Total', 'Item06Total', 'Item07Total',
'Total_Purchase', 'NJ_Tax', 'SH_Charge', 'Amount_To_Pay', 'CC1', 'CC2', 'CC3', 'CC4', 'Expires' )
VALUES ('$Name', '$Ad1', '$Ad2', '$City', '$State', '$Zip5', '$Zip4', '$Email', '$AreaCode', '$Phone3', '$Phone4', '$Ext',
'$Item01Qty', '$Item02Qty', '$Item03Qty',  '$Item04Qty', '$Item05Qty',  '$Item06Qty',  '$Item07Qty',
'$Item01Total', '$Item02Total', '$Item03Total', '$Item04Total', '$Item05Total', '$Item06Total', '$Item07Total',
'$Total_Purchase', '$NJ_Tax', '$SH_Charge', '$Amount_To_Pay', '$CC1', '$CC2', '$CC3', '$CC4', '$Expires' )";

mysql_query( $query );

echo "database updated";

           mysql_close($conn);

?>

  It still does not work.  Nothing is going into the database!??  :'(  Somebody please help! :confused:

Link to comment
Share on other sites

Ken...okay here is the result

Problem with the query: INSERT INTO capture ('Name', 'Ad1', 'Ad2', 'City', 'State', 'Zip5', 'Zip4', 'Email', 'AreaCode', 'Phone3', 'Phone4', 'Ext', 'Item01Qty', 'Item02Qty', 'Item03Qty', 'Item04Qty', 'Item05Qty', 'Item06Qty', 'Item07Qty', 'Item01Total', 'Item02Total', 'Item03Total', 'Item04Total', 'Item05Total', 'Item06Total', 'Item07Total', 'Total_Purchase', 'NJ_Tax', 'SH_Charge', 'Amount_To_Pay', 'CC1', 'CC2', 'CC3', 'CC4', 'Expires' ) VALUES ('888888888', '', '', '', '', '', '', '888888888888', '8888', '8888', '8888', '', '2', '', '', '', '', '', '', '13.30', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '13.30', '0.00', '6.20', '19.50', '8888', '888', '8888', '8888', '8888' )
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Name', 'Ad1', 'Ad2', 'City', 'State', 'Zip5', 'Zip4', 'Email', 'AreaCode', 'Pho' at line 2

  I am using EasyPHP 5.3 or so.  Where do I get a manual?  Do you think removing the single quote marks will solve this?

Link to comment
Share on other sites

The error message's suggestion to check the mysql manual - http://dev.mysql.com/doc/ for the correct syntax to use, is a generic syntax error when mysql cannot determine what you intended in your query. When you use the incorrect syntax at some point in your query, mysql can only determine that it found an element where it is not permitted. It cannot determine if you are using a feature that is present in some other version or if you simply did not learn the correct syntax that you should be using.

Link to comment
Share on other sites

:D Hooray, Hooray !  :D  I removed the quotes and the database updated successfully!

Thanks everyone for your help!  In closing, does anyone know of a good tutorial which will teach me how to extract the data from the database in a format that I can design, i.e.  I want each record to be printed out on a 81/2  x 11 piece of paper in a logical order.

Thanks again.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.