Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/03/2010, 07:57
liliana3186
 
Fecha de Ingreso: julio-2008
Mensajes: 2
Antigüedad: 15 años, 10 meses
Puntos: 0
Validar si se repite un campo y actulizar su cantidad + la que ingrese en PHP.

Tengo tres archivos, en los cuales ingresar compra es el formulario y en clase compra y controlad compratengo para insertar los datos en la base de datos de la compra de tarjetas (alli lo puedes ver).

Debo validar que si se repite algun nombre de tarjeta yo sume ese valor de la base de datos con el q estoy ingresando.

esta es Controladcompra:
<?php

include ('ManejadorBD.php');
include ('ClaseCompra.php');

$host="localhost";
$usuario="root";
$clave="";

$pname=$_POST['pname'];
$company= $_POST['company'];
$qty=$_POST['cant'];
$costprice=$_POST['cost'];
$salesprice=$_POST['sales'];

$boton=$_POST['boton'];

$objBD = new ManejadorBD();
$conexion=$objBD->conectarBD($host,$usuario,$clave);
//echo "se conecto<br>";

switch($boton){
case 'Send': {

if(($_POST['pname']!=null)and($_POST['company']!=null)and($_POST['cant']!=null)and($_POST['cost']!=null) and($_POST['sales']!=null) ) {
$comp= new ClaseCompra($pname,$company,$qty,$costprice,$sales price,$conexion,$objBD);
$comp->registrarCompra();

}
//break;
echo "<script> alert(window.status='Se ingresaron los datos correctamente');</script>";
//echo "<script>alert('hola');</script>";
echo "<script>window.location.href='http://localhost/kiosko/bienvenido.php';</script>";
}
}

?>

esta es ClaseCompra

<?php

class ClaseCompra{

private $conexion;
private $objBD;
private $query;
private $resultados;
private $registro;

public function ClaseCompra($pname,$company,$qty,$costprice,$sales price,$conexion,$objBD){
$this->conexion= $conexion;
$this->objBD= $objBD;
$this->set_pname($pname);
$this->set_company($company);
$this->set_qty($qty);
$this->set_costprice($costprice);
$this->set_salesprice($salesprice);
}// cierre de function Clase Compra

public function registrarCompra(){
$this->query="INSERT INTO kiosko.compra VALUES('".$this->get_pname()."','".$this->get_company()."','".$this->get_qty()."','".$this->get_costprice()."','".$this->get_salesprice()."');";
$this->resultados= $this->objBD->sentenciasSQL($this->query,$this->conexion);

}// cierre de registrarCompra

public function get_pname(){
return $this->pname;
}
public function set_pname($valor){
$this->pname = $valor;
}
public function get_company(){
return $this->company;
}
public function set_company($valor){
$this->company = $valor;
}
public function get_qty(){
return $this->qty;
}
public function set_qty($valor){
$this->qty = $valor;
}
public function set_costprice($valor){
$this->costprice = $valor;
}
public function get_costprice(){
return $this->costprice;
}
public function set_salesprice($valor){
$this->salesprice = $valor;
}
public function get_salesprice(){
return $this->salesprice;
}
}
?>