Foros del Web » Programando para Internet » PHP »

Django: 'user_id' IntegrityError columna no puede ser nulo

Estas en el tema de Django: 'user_id' IntegrityError columna no puede ser nulo en el foro de PHP en Foros del Web. Column 'user_id' cannot be null Código PHP: <?php  require_once( 'Connections/conexion.php' );  ?> <?php if (!isset( $_SESSION )) {    session_start (); } $MM_authorizedUsers  =  "" ; $MM_donotCheckaccess  ...
  #1 (permalink)  
Antiguo 25/04/2013, 14:48
 
Fecha de Ingreso: abril-2013
Mensajes: 39
Antigüedad: 11 años
Puntos: 0
Exclamación Django: 'user_id' IntegrityError columna no puede ser nulo

Column 'user_id' cannot be null
Código PHP:
<?php require_once('Connections/conexion.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 "index.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(
$_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0
  
$MM_referrer .= "?" $_SERVER['QUERY_STRING'];
  
$MM_restrictGoTo $MM_restrictGoTo$MM_qsChar "accesscheck=" urlencode($MM_referrer);
  
header("Location: "$MM_restrictGoTo); 
  exit;
}
?>
<?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"] == "form2")) {
  
$insertSQL sprintf("INSERT INTO Noticia (Foto, Temas, text, Video, Nombre, user_id) VALUES (%s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['Foto'], "text"),
                       
GetSQLValueString($_POST['Temas'], "text"),
                       
GetSQLValueString($_POST['text'], "text"),
                       
GetSQLValueString($_POST['Video'], "text"),
                       
GetSQLValueString($_POST['Nombre'], "text"),
                       
GetSQLValueString($_POST['user_id'], "text"));

  
mysql_select_db($database_conexion$conexion);
  
$Result1 mysql_query($insertSQL$conexion) or die(mysql_error());

  
$insertGoTo "index.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}

$colname_cuenta3 "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_cuenta3 $_SESSION['MM_Username'];
}
mysql_select_db($database_conexion$conexion);
$query_cuenta3 sprintf("SELECT * FROM usuario WHERE Usuarios = %s"GetSQLValueString($colname_cuenta3"text"));
$cuenta3 mysql_query($query_cuenta3$conexion) or die(mysql_error());
$row_cuenta3 mysql_fetch_assoc($cuenta3);
$totalRows_cuenta3 mysql_num_rows($cuenta3);
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>COCINA SORDA 2.0</title>
<link href="themas/htemas.css" rel="stylesheet" type="text/css">
</head>

<body>
<div class="contenedor">
<?php include("cabecera.php"); ?>
<?php 
include("menu.php"); ?>
<div class="contenido">
  <form method="post" name="form2" action="<?php echo $editFormAction?>">
    <table align="center">
      <tr valign="baseline">
        <td>Foto<br/><input type="text" name="Foto" value="" size="32"></td>
      </tr>
      <tr valign="baseline">
        <td>Titulo<br/><input type="text" name="Temas" value="" size="32"></td>
      </tr>
      <tr valign="baseline">
        <td>Texto<br/><textarea name="text" cols="32">te escribe</textarea></td>
      </tr>
      <tr valign="baseline">
        <td>http://youtu.be/<input type="text" name="Video" value="" size="32"></td>
      </tr>
      <tr valign="baseline">
        <td><input type="submit" value="Insertar registro"></td>
      </tr>
    </table>
    <input type="hidden" name="Nombre" value="<?php echo $row_cuenta3['Nombre']; ?> <?php echo $row_cuenta3['Apellido']; ?>">
    <input type="hidden" name="user_id" value="<?php echo $row_cuenta3['id']; ?>">
    <input type="hidden" name="MM_insert" value="form2">
  </form>
  <p>&nbsp;</p>
</div>
<?php include("pie.php"); ?>
</div>
</body>
</html>
<?php
mysql_free_result
($cuenta3);
?>
  #2 (permalink)  
Antiguo 25/04/2013, 15:25
 
Fecha de Ingreso: abril-2008
Ubicación: El Salvador
Mensajes: 736
Antigüedad: 16 años
Puntos: 47
Respuesta: Django: 'user_id' IntegrityError columna no puede ser nulo

no sos nada expresivo, deberias leer las normas del foro si quieres que alguien te ayude
  #3 (permalink)  
Antiguo 25/04/2013, 15:28
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Django: 'user_id' IntegrityError columna no puede ser nulo

Seguramente camilomascarell1987 es de los usuarios que creen que con solo mostrar código sin explicar nada del problema, ni síntomas, ni resultados cualquiera puede adivinar de que se trata.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #4 (permalink)  
Antiguo 25/04/2013, 15:33
 
Fecha de Ingreso: abril-2013
Mensajes: 39
Antigüedad: 11 años
Puntos: 0
Respuesta: Django: 'user_id' IntegrityError columna no puede ser nulo

el programa adobe dreamweaver cs6 y código es muy mal, porque?
conexion.php
Código 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;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  
session_start();
}

$loginFormAction $_SERVER['PHP_SELF'];
if (isset(
$_GET['accesscheck'])) {
  
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset(
$_POST['textfield'])) {
  
$loginUsername=$_POST['textfield'];
  
$password=md5($_POST['textfield2']);
  
$MM_fldUserAuthorization "";
  
$MM_redirectLoginSuccess "cuenta.php";
  
$MM_redirectLoginFailed "error.php";
  
$MM_redirecttoReferrer false;
  
mysql_select_db($database_conexion$conexion);
  
  
$LoginRS__query=sprintf("SELECT Usuarios, Password FROM usuario WHERE Usuarios=%s AND Password=%s",
    
GetSQLValueString($loginUsername"text"), GetSQLValueString($password"text")); 
    
  
$LoginRS mysql_query($LoginRS__query$conexion) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);
  if (
$loginFoundUser) {
     
$loginStrGroup "";
    
    if (
PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    
//declare two session variables and assign them
    
$_SESSION['MM_Username'] = $loginUsername;
    
$_SESSION['MM_UserGroup'] = $loginStrGroup;          

    if (isset(
$_SESSION['PrevUrl']) && false) {
      
$MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
    }
    
header("Location: " $MM_redirectLoginSuccess );
  }
  else {
    
header("Location: "$MM_redirectLoginFailed );
  }
}
?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  
session_start();
}

// ** Logout the current user. **
$logoutAction $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset(
$_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  
$logoutAction .="&"htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  
//to fully log out a visitor we need to clear the session varialbles
  
$_SESSION['MM_Username'] = NULL;
  
$_SESSION['MM_UserGroup'] = NULL;
  
$_SESSION['PrevUrl'] = NULL;
  unset(
$_SESSION['MM_Username']);
  unset(
$_SESSION['MM_UserGroup']);
  unset(
$_SESSION['PrevUrl']);
    
  
$logoutGoTo "index.php";
  if (
$logoutGoTo) {
    
header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?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;
}
}

$colname_cuenta "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_cuenta $_SESSION['MM_Username'];
}
mysql_select_db($database_conexion$conexion);
$query_cuenta sprintf("SELECT Nombre, Apellido, Correo, Usuarios, Password, avatar, altacuenta FROM usuario WHERE Usuarios = %s"GetSQLValueString($colname_cuenta"text"));
$cuenta mysql_query($query_cuenta$conexion) or die(mysql_error());
$row_cuenta mysql_fetch_assoc($cuenta);
$totalRows_cuenta mysql_num_rows($cuenta);
?>
  #5 (permalink)  
Antiguo 25/04/2013, 15:36
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Django: 'user_id' IntegrityError columna no puede ser nulo

Cita:
Iniciado por camilomascarell1987 Ver Mensaje
el programa adobe dreamweaver cs6 y código es muy mal, porque?
Es imposible determina una razón, no somos máquinas que adivinan con sólo leer código.

Si solo te la pasas pegando código no vamos a llegar a ningún lado, necesitas explicar más de lo que sucede, si recibes errores, etc.

Te sugiero leer lo siguiente:

Cómo hacer preguntas de manera inteligente
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #6 (permalink)  
Antiguo 25/04/2013, 15:38
 
Fecha de Ingreso: abril-2008
Ubicación: El Salvador
Mensajes: 736
Antigüedad: 16 años
Puntos: 47
Respuesta: Django: 'user_id' IntegrityError columna no puede ser nulo

Sigues sin decir cual es el problema, tampoco mencionas que soluciones has intentado, no veo que tiene que ver dreamweaver cs6

Cita:
código es muy mal, porque?
El codigo está mal porque haci esta hecho asi que para resolver el problema corrigelo...
  #7 (permalink)  
Antiguo 25/04/2013, 16:29
 
Fecha de Ingreso: abril-2013
Mensajes: 39
Antigüedad: 11 años
Puntos: 0
Respuesta: Django: 'user_id' IntegrityError columna no puede ser nulo

quiero programa otro marca cual? pero adobe dreamweaver cs 6 solo auto codigo php y mysql es muy problemas, mi ordenador sistemas MAC OS X 10.8.3 y XAMPP
  #8 (permalink)  
Antiguo 26/04/2013, 01:12
Avatar de NJS
NJS
 
Fecha de Ingreso: noviembre-2011
Mensajes: 371
Antigüedad: 12 años, 5 meses
Puntos: 28
Respuesta: Django: 'user_id' IntegrityError columna no puede ser nulo

Cual es el problema?? que error te aparece o que es lo que no sabes como hacer ¿¿??
__________________
Mejores empresas de Hosting
-=-=-=-=-=-=-=-
Empresas de Hosting
  #9 (permalink)  
Antiguo 26/04/2013, 06:11
 
Fecha de Ingreso: abril-2013
Mensajes: 34
Antigüedad: 11 años
Puntos: 3
Respuesta: Django: 'user_id' IntegrityError columna no puede ser nulo

estimado, me parece que no hablas español y tomaste el traductor de google para escribir aquí, de todas formas si necesitas otro programa para poder programar, te recomiendo netbeans, o sublime text

Etiquetas: columna, django, html, mysql, nulo, registro, select, sql, usuarios
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:47.