"Column cn_uso_id cannot be null"
Olá, amigos. A mensagem "Column cn_uso_id cannot be null" aparece quando eu tento inserir uma notícia. No babnco de dados, a opção está not null. O que eu devo alterar no código abaixo para sanar este problema?
Muito obrigado!
o código:
<?php require_once('../Connections/Curso_d.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);if (in_array($UserName, $arrUsers)) {
$isValid = true;
}// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "../admin/login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?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 = $_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 curso_noticias (cn_uso_id, cn_titulo, cn_data, cn_fonte, cn_status, cn_body) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['cn_uso_id'], "int"),
GetSQLValueString($_POST['cn_titulo'], "text"),
GetSQLValueString($_POST['cn_data'], "date"),
GetSQLValueString($_POST['cn_fonte'], "text"),
GetSQLValueString(isset($_POST['cn_status']) ? "true" : "", "defined","1","0"),
GetSQLValueString($_POST['cn_body'], "text"));
mysql_select_db($database_Curso_d, $Curso_d);
$Result1 = mysql_query($insertSQL, $Curso_d) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO curso_noticias (cn_uso_id, cn_titulo, cn_data, cn_fonte, cn_status, cn_body) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['cn_uso_id'], "int"),
GetSQLValueString($_POST['cn_titulo'], "text"),
GetSQLValueString($_POST['cn_data'], "date"),
GetSQLValueString($_POST['cn_fonte'], "text"),
GetSQLValueString(isset($_POST['cn_status']) ? "true" : "", "defined","1","0"),
GetSQLValueString($_POST['cn_body'], "text"));
mysql_select_db($database_Curso_d, $Curso_d);
$Result1 = mysql_query($insertSQL, $Curso_d) or die(mysql_error());
}
$colname_RsUserSession = "-1";
if (isset($_SESSION['MM_username'])) {
$colname_RsUserSession = (get_magic_quotes_gpc()) ? $_SESSION['MM_username'] : addslashes($_SESSION['MM_username']);
}
mysql_select_db($database_Curso_d, $Curso_d);
$query_RsUserSession = sprintf("SELECT * FROM curso_usuarios WHERE usu_email = '%s'", $colname_RsUserSession);
$RsUserSession = mysql_query($query_RsUserSession, $Curso_d) or die(mysql_error());
$row_RsUserSession = mysql_fetch_assoc($RsUserSession);
$totalRows_RsUserSession = mysql_num_rows($RsUserSession);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/index.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<script src="../includes/tiny_mce/tiny_mce/tiny_mce.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">tinyMCE.init({
mode : "textareas",
theme : "advanced",
plugins : "table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,contextmenu,paste,directionality,fullscreen",
theme_advanced_buttons1_add_before : "save,newdocument,separator",
theme_advanced_buttons1_add : "fontselect,fontsizeselect",
theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
theme_advanced_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator",
theme_advanced_buttons3_add_before : "tablecontrols,separator",
theme_advanced_buttons3_add : "emotions,iespell,flash,advhr,separator,print,separator,ltr,rtl,separator,fullscreen",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
content_css : "example_word.css",
content_css : "http://localhost/mgctpw/templates/mambo_admin_blue/css/template_css.css",
plugi2n_insertdate_dateFormat : "%Y-%m-%d",
plugi2n_insertdate_timeFormat : "%H:%M:%S",
external_link_list_url : "example_link_list.js",
external_image_list_url : "example_image_list.js",
flash_external_list_url : "example_flash_list.js",
file_browser_callback : "fileBrowserCallBack",
paste_use_dialog : false,
theme_advanced_resizing : true,
theme_advanced_resize_horizontal : false,
theme_advanced_link_targets : "_something=My somthing;_something2=My somthing2;_something3=My somthing3;",
paste_auto_cleanup_on_paste : true,
paste_convert_headers_to_strong : false,
paste_strip_class_attributes : "all",
paste_remove_spans : false,
paste_remove_styles : false
});
function fileBrowserCallBack(field_name, url, type, win) {
// This is where you insert your custom filebrowser logic
alert("Filebrowser callback: field_name: " + field_name + ", url: " + url + ", type: " + type);
// Insert new URL, this would normaly be done in a popup
win.document.forms[0].elements[field_name].value = "someurl.htm";
}
</script><!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
<style type="text/css"><!--
.style2 {color: #FFFFFF}
-->
</style>
<!-- InstanceEndEditable -->
<link href="../Templates/247shock_blue/css/template_css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="785" align="center" bgcolor="#CC0000">
<tr>
<td><table width="780" align="center" bgcolor="#FFFFFF">
<tr>
<td height="120"><img src="../imagens/layout_mcg_final.jpg" width="779" height="137" /></td>
</tr>
<tr>
<td bgcolor="#CCE3FD">Home Page | Serviços | Empresa | Notícias | Sobre Nós </td>
</tr>
<tr>
<td><!-- InstanceBeginEditable name="conteudo" -->
<table width="100%">
<tr>
<td></td>
</tr>
<tr>
<td background="../admin/index.php" bgcolor="#8C8CFF"><a href="index.php">Página Admin Notícias</a> <span class="style2">|</span> <a href="../admin/index.php">Página Admin do Site</a> <span class="style2">|</span><strong> <?php echo $_SESSION['MM_Username']; ?></strong></td>
</tr>
<tr>
<td>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr align="left" valign="baseline">
<td nowrap bgcolor="#F0F8FF"><div align="center"><strong>Título:</strong></div></td>
<td bgcolor="#F0F8FF"><input name="cn_titulo" type="text" value="" size="60" maxlength="80"></td>
</tr>
<tr align="left" valign="baseline">
<td nowrap bgcolor="#F0F8FF"><div align="center"><strong>Data:</strong></div></td>
<td bgcolor="#F0F8FF"><input name="cn_data" type="text" readonly="true" value="<?php echo date('y/m/d'); ?>" size="10" maxlength="10"></td>
</tr>
<tr align="left" valign="baseline">
<td nowrap bgcolor="#F0F8FF"><div align="center"><strong>Fonte:</strong></div></td>
<td bgcolor="#F0F8FF"><input name="cn_fonte" type="text" value="" size="60" maxlength="80"></td>
</tr>
<tr align="left" valign="baseline">
<td nowrap bgcolor="#F0F8FF"><div align="center"><strong>Status:</strong></div></td>
<td bgcolor="#F0F8FF"><input type="checkbox" name="cn_status" value="" >
<span class="style1">Selecione para ativar a notícia </span></td>
</tr>
<tr align="left" valign="baseline" bgcolor="#CCE3FD">
<td colspan="2" nowrap><strong>Conteúdo</strong></td>
</tr>
<tr align="left" valign="baseline">
<td colspan="2" valign="top" nowrap>:
<textarea name="cn_body" cols="90" rows="5"></textarea> </td>
</tr>
<tr align="left" valign="baseline">
<td colspan="2" nowrap bgcolor="#CCE3FD"><input type="submit" value="Inserir Notícia"></td>
</tr>
</table>
<input type="hidden" name="cn_uso_id" value= "<?php echo $row_RsUserSession['usu_id']; ?>">
<input type="hidden" name="MM_insert" value="form1">
</form> </td>
</tr>
</table>
<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td bgcolor="#CCE3FD"><div align="center">© Curso Avançado de Dreamweaver 8 </div></td>
</tr>
</table></td>
</tr>
</table>
</body><!-- InstanceEnd -->
</html>
<?php
mysql_free_result($RsUserSession);
?>Discussão (4)
Carregando comentários...