Jump to content

My form will not accept "null" values


sokaris

Recommended Posts

I hope I'm posting in the right spot. I'm working on a form where the PHP script was created by Dreamweaver's data wizard. It works great excepts that the "phone" and "commentMLS" data fields won't accept empty (null?) values. "name" and "email" fields have spry validation; "beds","baths", "priceRange" are menus, they work fine; the loan checkbox also works fine.

 

This is the error I get with an empty "phone" data field: "Column 'phone' cannot be null"

 

Thanks in advance for any help fixing this problem.

 

Here's the PHP script:

 

<?php require_once('Connections/rocklin3_client.php'); ?>

<?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 client (name, email, phone, commentIndex, loan) VALUES (%s, %s, %s, %s, %s)",

                      GetSQLValueString($_POST['name'], "text"),

                      GetSQLValueString($_POST['email'], "text"),

                      GetSQLValueString($_POST['phone'], "text"),

                      GetSQLValueString($_POST['commentIndex'], "text"),

                      GetSQLValueString(isset($_POST['loan']) ? "true" : "", "defined","1","0"));

 

  mysql_select_db($database_rocklin3_client, $rocklin3_client);

  $Result1 = mysql_query($insertSQL, $rocklin3_client) or die(mysql_error());

 

  $insertGoTo = "thank.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

    $insertGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $insertGoTo));

}

?>

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.