Foros del Web » Programando para Internet » PHP »

[AYUDA, Urgente] error ingresando datos

Estas en el tema de [AYUDA, Urgente] error ingresando datos en el foro de PHP en Foros del Web. tento un problema y es el siguiente... hice un sistema de noticias sencillito pero ahora no me esta scribiendo los datos en el sql... quisiera ...
  #1 (permalink)  
Antiguo 13/11/2007, 07:52
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
[AYUDA, Urgente] error ingresando datos

tento un problema y es el siguiente... hice un sistema de noticias sencillito pero ahora no me esta scribiendo los datos en el sql... quisiera saber q problemas tngo... si alguien pudiese ayudarme aqui les dejo mi codigo...
gracias
Código PHP:
<?php require_once('../../Connections/listproduc.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$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 noticias (id, titulo, contenido) VALUES (%s, %s, %s)",
                       
GetSQLValueString($_POST['id'], "int"),
                       
GetSQLValueString($_POST['titulo'], "text"),
                       
GetSQLValueString($_POST['contenido'], "text"));

  
mysql_select_db($database_listproduc$listproduc);
  
$Result1 mysql_query($insertSQL$listproduc) or die(mysql_error());
}
?><?php include ('../../Connections/listproduc.php');



    if (isset(
$_POST['subir'])) {

            
extract($_POST);



            if (empty(
$activo)){

            
$activo=2;

            }





        
$query="INSERT INTO noticias SET

        contenido = '$contenido',

        titulo = '$titulo'"
;    

        
mysql_query($query);

                                    

        
$msj="Su registro ha sido agregado con éxito";

    }            

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.Estilo16 {color: #FFFFFF}
-->
</style>
<link href="../../css2/estilo.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript">
function validar_archivo(archivo) {
    var error_archivo;
    error_archivo=0;
      var file=archivo.value;
      
          if (file=="")
          { error_archivo=1; }
          //texto += "\n\nIngrese Foto"
            else{
             
                 // file=document.formulario.FOTO.value
               extArray = new Array(".gif",".jpg");
               // Extension de archivos permitidos
               allowSubmit = false;
                 if (!file) return;

                   while (file.indexOf("\\") != -1)
                       file = file.slice(file.indexOf("\\") + 1);
                       ext = file.slice(file.indexOf(".")).toLowerCase();
                   
                   for (var i=0; i < extArray.length; i++){
                          if (extArray[i] == ext){
                             allowSubmit = true;
                             break;
                            }
                    }

                        if (!allowSubmit) {
                         error_archivo=2;
                        // texto += "\n\nFOTO: solo admite archivo con la extensión ''gif, .jpeg , .jpg''";
                         }
                            }
                            return error_archivo;
}



</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//-->
</script>
<style type="text/css">
<!--
.style1 {color: #000000}
-->
</style>
</head>

<body>
<div align="center">
  <TABLE height=243 cellSpacing=0 cellPadding=0 width=698 
background=../../images2/img/med.gif border=0>
    <CENTER>
      <TBODY>
        <TR>
          <TD width="100%" height=50 align="left" valign="top"><img src="../../images/panel.jpg" width="698" height="100"></TD>
        </TR>
    </CENTER>
    <CENTER>
    </CENTER>
    <TR>
      <TD width="100%" height=160 vAlign=top>
        <TABLE width=698 border=0 cellPadding=0 cellSpacing=0 bordercolor="#FF0000" id=table2>
          <TBODY>
            <TR>
              <TD width="8" vAlign=top > </TD>
              <TD width="156" vAlign=top class="nucomplet" ><?php include("../modulos/indexbarra.php"); ?>
              </TD>
              <TD width=10 vAlign=top> </TD>
              <TD width=13 vAlign=top> </TD>
              <TD width=498 align="center" vAlign=middle class="nucomplet"><span class="unnamed1"><a href="ingresar.php"> Insertar Noticias </a><span class="style1">-</span><a href="listado.php"> Administrar Noticias</a></span>
                <form name="form1" method="post" action="">
                </form>
              
                <form method="post" name="form2" action="<?php echo $editFormAction?>">
                  <table align="center">
                    <tr valign="baseline">
                      <td nowrap align="right">Titulo:</td>
                      <td><input type="text" name="titulo" value="" size="32"></td>
                    </tr>
                    <tr valign="baseline">
                      <td nowrap align="right" valign="top">Contenido:</td>
                      <td><textarea name="contenido" cols="30" rows="5"></textarea></td>
                    </tr>
                    <tr valign="baseline">
                      <td nowrap align="right">&nbsp;</td>
                      <td><input type="submit" value="Insertar"></td>
                    </tr>
                  </table>
                  <input type="hidden" name="id" value="">
                  <input type="hidden" name="MM_insert" value="form2">
                </form>
              <p>&nbsp;</p></TD>
              <TD width=13 vAlign=top>&nbsp;</TD>
            </TR>
          </TBODY>
      </TABLE></TD>
    </TR>
    <TR>
      <TD width="100%" height=33 valign="top" bgcolor="#FFFFFF" class="Estilo16">&nbsp;</TD>
    </TR>
  </TABLE>
</div>
<p align="center">&nbsp;</p>
</body>
</html>
  #2 (permalink)  
Antiguo 13/11/2007, 08:04
Avatar de rogertm
Mod->Cuba
 
Fecha de Ingreso: julio-2005
Ubicación: /home/Cuba/Habana/rogertm/
Mensajes: 2.922
Antigüedad: 18 años, 8 meses
Puntos: 638
Re: [AYUDA, Urgente] error ingresando datos

hola, creo que el problema que tienes es que en tu consulta INSERT estas inseertando el id de la noticia, y en realidad no lo necesitas, pero fijate que en tu tabla este campo sea autoincremet, hazlo asi:
Código PHP:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) { 
  
$insertSQL sprintf("INSERT INTO noticias (titulo, contenido) VALUES (%s, %s, %s)",
                       
GetSQLValueString($_POST['titulo'], "text"), 
                       
GetSQLValueString($_POST['contenido'], "text")); 
saludos y suerte
__________________
Friki y Blogger por Cuenta Propia:213
Twenty'em: Theming is Prose
  #3 (permalink)  
Antiguo 13/11/2007, 08:08
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: [AYUDA, Urgente] error ingresando datos

Gracias hermano... funciono a la perfeccion....
  #4 (permalink)  
Antiguo 13/11/2007, 08:11
Avatar de rogertm
Mod->Cuba
 
Fecha de Ingreso: julio-2005
Ubicación: /home/Cuba/Habana/rogertm/
Mensajes: 2.922
Antigüedad: 18 años, 8 meses
Puntos: 638
Re: [AYUDA, Urgente] error ingresando datos

na, aqui estamos pa servir
__________________
Friki y Blogger por Cuenta Propia:213
Twenty'em: Theming is Prose
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 00:53.