Foros del Web » Programando para Internet » PHP »

insertar factura segun usuario de session

Estas en el tema de insertar factura segun usuario de session en el foro de PHP en Foros del Web. Saludos muchachos, poseo mis dos tablas Tabla Clientes id <-int nombre apellido usuario pass mail cedula telefono fecha y Tabla Factura id <- int factura ...
  #1 (permalink)  
Antiguo 19/06/2008, 09:04
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 7 meses
Puntos: 28
insertar factura segun usuario de session

Saludos muchachos,
poseo mis dos tablas
Tabla Clientes
id <-int
nombre
apellido
usuario
pass
mail
cedula
telefono
fecha

y Tabla Factura
id <- int
factura
tienda
monto
cedula <- int

pero n cedula de la tabla factura se debe ingresar el id del cliente....

perfecto hasta aqui lo entiendo... y creo estar en lo correcto ... "DIOS QUIERA"

ahora solo quisiera saber si cuando logueo en mi session como un usuario X o Y y entro en mi perfil o ficha tecnica al yo hacer click en el menu y querer ingersar una factura en mi session este seria la manera correcta
Código PHP:
<?php require_once('conect.php'); ?>
<?php
$rec 
"-1";
if (isset(
$_SESSION['id'])) {
  
$rec $_SESSION['id'];
}
$sql="select * from clientes where id = '$rec'";
        
$sql_exec mysql_query($sql);
        
$rec mysql_fetch_array($sql_exec);
?>
<?php 
require_once('../Connections/pintor.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"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO factura (id, factura, tienda, monto, cedula) VALUES (%s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['id'], "int"),
                       
GetSQLValueString($_POST['factura'], "text"),
                       
GetSQLValueString($_POST['tienda'], "text"),
                       
GetSQLValueString($_POST['monto'], "text"),
                       
GetSQLValueString($_POST['cedula'], "int"));

  
mysql_select_db($database_pintor$pintor);

$sqlex mysql_query("SELECT id FROM clientes WHERE id='".$_POST['cedula']."'"$conexion);   
$num_rows mysql_num_rows($sqlex);  
$usuario "";
if(
mysql_num_rows($sqlex)==0)  

$usuario "Este usuario se encuentra registrado en el sistema"; } 

//asi si ya existe solo dira que existe y el mysql_query ya no ejecuta el query del insert creo yo 
else   

  
$Result1 mysql_query($insertSQL$pintor) or die(mysql_error());

  
$insertGoTo "gr_fact_x2.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}
?>
Gracias!!!!
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #2 (permalink)  
Antiguo 19/06/2008, 09:10
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: insertar factura segun usuario de session

Creo en lugar de insertar $_POST['id'] deberías de insertar (para mayor seguridad) $_SESSION['id'] ya que ahí es donde guardas tu variable que identifica al usuario..

Saludos.
  #3 (permalink)  
Antiguo 19/06/2008, 09:37
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 7 meses
Puntos: 28
Respuesta: insertar factura segun usuario de session

Código PHP:
GetSQLValueString($_SESSION['id'], "int"), 
Gator... lo q me gustaria es como envio a cedula el id de la session para q se inserte como datoº
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #4 (permalink)  
Antiguo 19/06/2008, 09:46
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 7 meses
Puntos: 28
Respuesta: insertar factura segun usuario de session

listo gator... fijate lo q hice

Código PHP:
<?php require_once ('includes/sesion.php');
require_once(
'conect.php'); 

$reco "-1";
if (isset(
$_SESSION['id'])) {
  
$reco $_SESSION['id'];
}
$sql="select * from clientes where id = '$reco'";
        
$sql_exec mysql_query($sql);
        
$rec mysql_fetch_array($sql_exec);
?>
<?php 
require_once('../Connections/pintor.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"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO factura (id, factura, tienda, monto, id_user) VALUES (%s, %s, %s, %s, $reco)",
                       
GetSQLValueString($_POST['id'], "int"),
                       
GetSQLValueString($_POST['factura'], "text"),
                       
GetSQLValueString($_POST['tienda'], "text"),
                       
GetSQLValueString($_POST['monto'], "text"),
                       
GetSQLValueString($_POST['id_user'], "int"));

  
mysql_select_db($database_pintor$pintor);

  
$Result1 mysql_query($insertSQL$pintor) or die(mysql_error());

  
$insertGoTo "gr_fact_x2.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}
?>
pero = sigue en pie mi pregunta anterior.. como lo hago con $_SESSION['id']
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #5 (permalink)  
Antiguo 19/06/2008, 11:26
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: insertar factura segun usuario de session

Por lo que veo ya haces un Query y descargas los datos en $rec, lo que podrías hacer es usar $rec['cedula'] para insertarla en tu campo facturas.

Saludos.
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 05:40.