poseo mis dos tablas
Tabla Clientes
id <-int
nombre
apellido
usuario
pass
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));
}
?>