Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Entering Data in MYSQL

Status
Not open for further replies.

hebisr3

Programmer
Feb 17, 2004
5
US
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

<?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));
}
?>
 
Just as the error says.

The column "breed" in your table is defined to be "not null", but your code is trying to insert a null value.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Can you display the query ($insertSQL) before it gets inserted for us please
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top