la richiestra in realtà era proprio su come fare la query se alcuni campi sono vuoti.
Se con il form mando tutti i campi tramite POST nella pagina php li ricevo tutti, alcuni vuoti e alcuni "pieni".
Come faccio ad inserire i pieni in una query?
Ho provato a fare una cosa del genere ma ho problemi con la condizione WHERE:
Codice PHP:
<?php
//Retreive information from form
$kind=$_POST["kind"];
$position=$_POST["position"];
$size=$_POST["size"];
$price=$_POST["price"];
$event=$_POST["event"];
$weather=$_POST["weather"];
$name=$_POST["name"];
$pur_date=$_POST["pur_date"];
$color=$_POST["color"];
if (!empty($kind)){
$campi="kind"." ";
$valorekind=$kind;
$where="kind="."'".$kind."'"."AND ";
}
if (!empty($position)){
$campi=$campi."position"." ";
$valoreposition=$position;
$where=$where."position="."'".$position."'"." AND ";
}
if (!empty($size)){
$campi=$campi."size"." ";
$valoresize=$size;
$where="size="."'".$size."'"." AND ";
}
if (!empty($price)){
$campi=$campi."price"." ";
$valoreprice=$price;
$where="price="."'".$price."'"." AND ";
}
if (!empty($event)){
$campi=$campi."event"." ";
$valoreevent=$event;
$where="event="."'".$event."'"." AND ";
}
if (!empty($weather)){
$campi=$campi."weather"." ";
$valoreweather=$weather;
$where="weather="."'".$weather."'"." AND ";
}
if (!empty($name)){
$campi=$campi."name"." ";
$valorename=$name;
$where="name="."'".$name."'"." AND ";
}
if (!empty($pur_date)){
$campi=$campi."pur_date"." ";
$valorepur_date=$pur_date;
$where="pur_date="."'".$pur_date."'"." AND ";
}
if (!empty($color)){
$campi=$campi."color"." ";
$valorecolor=$color;
$where=$where."color="."'".$color."'"." AND ";
}
$query= "SELECT ".$campi."FROM clothes WHERE ".$where ;echo($query);?>