If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Entering Data

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-15-04, 12:21
Chessa Chessa is offline
Registered User
 
Join Date: Apr 2004
Posts: 6
Entering Data

HI there fellas,
I am currently working on this piece of code and is experiencing some difficulties here:

The Objective of this piece of code is to enter some data in a from and then hit submit: the information will then immediately go into the database.

The Error:
I received the error:
Column 'breed' cannot be null

I really don't understand what's happening here....

Here's the code for the insert data page

[code]
<?php require_once('Connections/connPets.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "insert_dat")) {
$insertSQL = sprintf("INSERT INTO adoption_list (species, breed, name, age, personality) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['species'], "text"),
GetSQLValueString($HTTP_POST_VARS['breed'], "text"),
GetSQLValueString($HTTP_POST_VARS['name'], "text"),
GetSQLValueString($HTTP_POST_VARS['age'], "int"),
GetSQLValueString($HTTP_POST_VARS['personality'], "text"));

mysql_select_db($database_connPets, $connPets);
$Result1 = mysql_query($insertSQL, $connPets) or die(mysql_error());

$insertGoTo = "insert_yeah.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
Reply With Quote
  #2 (permalink)  
Old 04-15-04, 18:31
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
Re: Entering Data

Sounds like in your table declaration you have set the breed column to not null. Somewhere in your data conversion you are passing a null value to breed which is what is generating the error. If you are passing the right values to breed (i.e. it is supposed to be text and you are passing text), then you might want to check your script without the CASE logic below and see if that works. I think that might be the part you may have to rewrite out of any of it.

Quote:
Originally posted by Chessa
HI there fellas,
I am currently working on this piece of code and is experiencing some difficulties here:

The Objective of this piece of code is to enter some data in a from and then hit submit: the information will then immediately go into the database.

The Error:
I received the error:
Column 'breed' cannot be null

I really don't understand what's happening here....

Here's the code for the insert data page

[code]
<?php require_once('Connections/connPets.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "insert_dat")) {
$insertSQL = sprintf("INSERT INTO adoption_list (species, breed, name, age, personality) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['species'], "text"),
GetSQLValueString($HTTP_POST_VARS['breed'], "text"),
GetSQLValueString($HTTP_POST_VARS['name'], "text"),
GetSQLValueString($HTTP_POST_VARS['age'], "int"),
GetSQLValueString($HTTP_POST_VARS['personality'], "text"));

mysql_select_db($database_connPets, $connPets);
$Result1 = mysql_query($insertSQL, $connPets) or die(mysql_error());

$insertGoTo = "insert_yeah.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On