Jump to content

Mysql V5.0.51 php form help


hunter85

Recommended Posts

Hello,

I am totally new to mysql/php i have a marquee business and I have followed a tutorial to create a basic form for my customers to fill out to request details. The db fields are general sort of thing name address phone number etc with a couple of drop down lists on the form created in dw i have linked the db and the form together okay. All of the field types I have are varchar following the tutorial and not null. when testing the form I get error Column 'phone no' cannot be null so I thought it may have to be "int" or "bigint" didn’t make no difference and the postcode field doesn’t actually input the data typed nor does the drop down list and just puts a single number. not only this when the form is submitted it send it 6 times to the db I have done something seriously wrong or have I missed some code or what? . Can anybody link me to a good tutorial or lend a helping hand.

 

regards

Dan

 

Link to comment
Share on other sites

ok right is it the following...

 

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $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"] == "userform")) {
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['town'], "text"),
                       GetSQLValueString($_POST['county'], "text"));

  mysql_select_db($database_lmhc, $lmhc);
  $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) {
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['town'], "text"),
                       GetSQLValueString($_POST['county'], "text"));

  mysql_select_db($database_lmhc, $lmhc);
  $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) {
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['town'], "text"),
                       GetSQLValueString($_POST['county'], "text"));

  mysql_select_db($database_lmhc, $lmhc);
  $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) {
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['town'], "text"),
                       GetSQLValueString($_POST['county'], "text"));

  mysql_select_db($database_lmhc, $lmhc);
  $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) {
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['town'], "text"),
                       GetSQLValueString($_POST['county'], "text"));

  mysql_select_db($database_lmhc, $lmhc);
  $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) {
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['town'], "text"),
                       GetSQLValueString($_POST['county'], "text"));

  mysql_select_db($database_lmhc, $lmhc);
  $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) {
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['town'], "text"),
                       GetSQLValueString($_POST['county'], "text"));

  mysql_select_db($database_lmhc, $lmhc);
  $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) {
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county, postcode, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['town'], "text"),
                       GetSQLValueString($_POST['county'], "text"),
                       GetSQLValueString($_POST['postcode'], "text"),
                       GetSQLValueString($_POST['email'], "text"));

  mysql_select_db($database_lmhc, $lmhc);
  $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) {
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county, postcode, `phone no`, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['town'], "text"),
                       GetSQLValueString($_POST['county'], "text"),
                       GetSQLValueString($_POST['postcode'], "text"),
                       GetSQLValueString($_POST['phone no'], "text"),
                       GetSQLValueString($_POST['email'], "text"));

  mysql_select_db($database_lmhc, $lmhc);
  $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) {
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county, postcode, `phone no`, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['town'], "text"),
                       GetSQLValueString($_POST['county'], "text"),
                       GetSQLValueString($_POST['postcode'], "text"),
                       GetSQLValueString($_POST['phone no'], "text"),
                       GetSQLValueString($_POST['email'], "text"));

  mysql_select_db($database_lmhc, $lmhc);
  $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) {
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county, postcode, `phone no`, `mobile no`, `site address`, `date of function`, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['town'], "text"),
                       GetSQLValueString($_POST['county'], "text"),
                       GetSQLValueString($_POST['postcode'], "text"),
                       GetSQLValueString($_POST['phone no'], "text"),
                       GetSQLValueString($_POST['mobile no'], "text"),
                       GetSQLValueString($_POST['site address'], "text"),
                       GetSQLValueString($_POST['date of function'], "date"),
                       GetSQLValueString($_POST['email'], "text"));

  mysql_select_db($database_lmhc, $lmhc);
  $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) {
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county, postcode, `date of function`, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['town'], "text"),
                       GetSQLValueString($_POST['county'], "text"),
                       GetSQLValueString($_POST['postcode'], "text"),
                       GetSQLValueString($_POST['date of function'], "date"),
                       GetSQLValueString($_POST['email'], "text"));

  mysql_select_db($database_lmhc, $lmhc);
  $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) {
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county, postcode, `phone no`, `mobile no`, `site address`, `date of function`, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['town'], "text"),
                       GetSQLValueString($_POST['county'], "text"),
                       GetSQLValueString($_POST['postcode'], "text"),
                       GetSQLValueString($_POST['phone no'], "text"),
                       GetSQLValueString($_POST['mobile no'], "text"),
                       GetSQLValueString($_POST['site address'], "text"),
                       GetSQLValueString($_POST['date of function'], "date"),
                       GetSQLValueString($_POST['email'], "text"));

  mysql_select_db($database_lmhc, $lmhc);
  $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform")) {
  $insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, county, postcode, `phone no`, `mobile no`, `site address`, `date of function`, `type of function`, `no of guests`, `is the function a surprise`, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['firstName'], "text"),
                       GetSQLValueString($_POST['lastName'], "text"),
                       GetSQLValueString($_POST['address1'], "text"),
                       GetSQLValueString($_POST['address2'], "text"),
                       GetSQLValueString($_POST['town'], "text"),
                       GetSQLValueString($_POST['county'], "text"),
                       GetSQLValueString($_POST['postcode'], "text"),
                       GetSQLValueString($_POST['phone no'], "text"),
                       GetSQLValueString($_POST['mobile no'], "text"),
                       GetSQLValueString($_POST['site address'], "text"),
                       GetSQLValueString($_POST['date of function'], "date"),
                       GetSQLValueString($_POST['type of function'], "text"),
                       GetSQLValueString($_POST['no of guests'], "text"),
                       GetSQLValueString($_POST['is the function a surprise'], "text"),
                       GetSQLValueString($_POST['email'], "text"));

  mysql_select_db($database_lmhc, $lmhc);
  $Result1 = mysql_query($insertSQL, $lmhc) or die(mysql_error());
}

ok am i right in thinking that it is repeated several times which is where the multple entries are coming from

thanks dan

Link to comment
Share on other sites

That's your ENTIRE code block -- not very helpful.

 

And yes, no need to repeat everything!  Also, there's a space in your column name... difficult to work with in the long-run.

 

what i'd like to see if an echo of $insertSQL along with your die() statement -- and figure out which one it is.

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.