Jump to content

Records don't insert and errors don't appear


SauloA

Recommended Posts

When submitting the form, the records are sometimes inserted and sometimes not.  I receive no errors stating what the problem is.

 

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO customer_tbl (customer_first_name, customer_last_name, customer_company, customer_ac, customer_phone, customer_fax_ac, customer_fax_phone, customer_email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['customer_first_name'], "text"),
                       GetSQLValueString($_POST['customer_last_name'], "text"),
                       GetSQLValueString($_POST['customer_company'], "text"),
                       GetSQLValueString($_POST['customer_ac'], "text"),
                       GetSQLValueString($_POST['customer_phone'], "text"),
                       GetSQLValueString($_POST['customer_fax_ac'], "text"),
                       GetSQLValueString($_POST['customer_fax_phone'], "text"),
                       GetSQLValueString($_POST['customer_email'], "text"));

$customer_id = false;
if(mysql_query($insertSQL, $connCid))
	$customer_id = mysql_insert_id();
else
	echo "There was an error.";
}
  
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO quote_request_tbl (customer_id, quote_trans_date, quote_from_company, quote_from_address, quote_from_city, quote_from_state, quote_from_zip, quote_to_company, quote_to_address, quote_to_city, quote_to_state, quote_to_zip, quote_comments) VALUES ('$customer_id', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['quote_trans_date'], "text"),
                       GetSQLValueString($_POST['quote_from_company'], "text"),
                       GetSQLValueString($_POST['quote_from_address'], "text"),
                       GetSQLValueString($_POST['quote_from_city'], "text"),
                       GetSQLValueString($_POST['quote_from_state'], "text"),
                       GetSQLValueString($_POST['quote_from_zip'], "text"),
                       GetSQLValueString($_POST['quote_to_company'], "text"),
                       GetSQLValueString($_POST['quote_to_address'], "text"),
                       GetSQLValueString($_POST['quote_to_city'], "text"),
                       GetSQLValueString($_POST['quote_to_state'], "text"),
                       GetSQLValueString($_POST['quote_to_zip'], "text"),
                       GetSQLValueString($_POST['quote_comments'], "text"));
  
  $quote_id = false;
if(mysql_query($insertSQL, $connCid))
	$quote_id = mysql_insert_id();
else
	echo "There was an error.";
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && (isset($quote_id))) {
  $insertSQL = sprintf("INSERT INTO building_tbl (quote_id, building_quantity, building_width, building_length, building_height, building_overhang, slope_id, building_type_id, manufacture_id, foundation_id) VALUES ('$quote_id', %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['building_quantity1'], "int"),
                       GetSQLValueString($_POST['building_width1'], "int"),
                       GetSQLValueString($_POST['building_length1'], "int"),
                       GetSQLValueString($_POST['building_height1'], "int"),
                       GetSQLValueString($_POST['building_overhang1'], "int"),
                       GetSQLValueString($_POST['slope_id1'], "int"),
                       GetSQLValueString($_POST['building_type_id1'], "int"),
                       GetSQLValueString($_POST['manufacture_id1'], "int"),
                       GetSQLValueString($_POST['foundation_id1'], "int");

  mysql_select_db($database_connCid, $connCid);
  $Result1 = mysql_query($insertSQL, $connCid) or die(mysql_error());

header('Location: index.php?view=article&id=7');
}

mysql_select_db($database_connCid, $connCid);
$query_rsSlope = "SELECT * FROM slope_tbl ORDER BY slope_id ASC";
$rsSlope = mysql_query($query_rsSlope, $connCid) or die(mysql_error());
$row_rsSlope = mysql_fetch_assoc($rsSlope);
$totalRows_rsSlope = mysql_num_rows($rsSlope);
$query_rsSlope = "SELECT * FROM slope_tbl ORDER BY slope_id ASC";
$rsSlope = mysql_query($query_rsSlope, $connCid) or die(mysql_error());
$row_rsSlope = mysql_fetch_assoc($rsSlope);
$totalRows_rsSlope = mysql_num_rows($rsSlope);

mysql_select_db($database_connCid, $connCid);
$query_rsBuildingType = "SELECT * FROM building_type_tbl ORDER BY building_type_id ASC";
$rsBuildingType = mysql_query($query_rsBuildingType, $connCid) or die(mysql_error());
$row_rsBuildingType = mysql_fetch_assoc($rsBuildingType);
$totalRows_rsBuildingType = mysql_num_rows($rsBuildingType);

mysql_select_db($database_connCid, $connCid);
$query_rsManufacture = "SELECT * FROM manufacture_tbl ORDER BY manufacture_name ASC";
$rsManufacture = mysql_query($query_rsManufacture, $connCid) or die(mysql_error());
$row_rsManufacture = mysql_fetch_assoc($rsManufacture);
$totalRows_rsManufacture = mysql_num_rows($rsManufacture);

mysql_select_db($database_connCid, $connCid);
$query_rsFoundation = "SELECT * FROM foundation_tbl ORDER BY foundation_name ASC";
$rsFoundation = mysql_query($query_rsFoundation, $connCid) or die(mysql_error());
$row_rsFoundation = mysql_fetch_assoc($rsFoundation);
$totalRows_rsFoundation = mysql_num_rows($rsFoundation);
?>

 

I belve the problem is in this part of the code:

 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && (isset($quote_id)))

 

Many thanks in advance.

to see your error put @ in mysql for example

@mysql_query($query,$con) or die ("Error: $query ".mysql_error());

 

and in your $_POST['MM_insert'] == 'form1' why not just check the value of your submit button?

like

if (isset($_POST['your_submit_button_name']))

{

// your insert goes here.

}

 

and your insert why not just make it simple?, example

 

$query =  "insert into mytable(name,age) values('yourname','12')";

@mysql_query($query,$con) or die ("Error: $query ".mysql_error());

 

even if you put '12' with quote it will be converted to the datatype of your column. bec that is what i am doing and it is working good.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.