Salve,
avrei bisogno di una mano..
ho un modulo dentro il quale c'è un campo di testo ($review) ma quando nel campo viene inserito un apostrofo la stringa non viene salvata nel db perché ovviamente l'apostrofo la interrompe..
Ora, ho letto che ci sono due modi:
- htmlspecialchar
- mysql_real_escape_string()
il problema è che non saprei dove inserirli..ho fatto un paio di tentativi ma a vuoto..
Posto il codice che scrive nel DB..
codice:
include "db.php";
$q=mysql_query("select * from site where id=1");
$s=mysql_fetch_assoc($q);
$site_approve=$s['approve'];
$title=isset($_POST['title'])?$_POST['title']:"";
$review=isset($_POST['review'])?$_POST['review']:"";
$name=isset($_POST['name'])?$_POST['name']:"";
$url=isset($_POST['url'])?$_POST['url']:"";
$location=isset($_POST['location'])?$_POST['location']:"";
$id=isset($_POST['hid'])?$_POST['hid']:0;
$tech=isset($_POST['tech'])?$_POST['tech']:0;
$cust=isset($_POST['cust'])?$_POST['cust']:0;
$sw=isset($_POST['sw'])?$_POST['sw']:0;
$traf=isset($_POST['traf'])?$_POST['traf']:0;
$rel=isset($_POST['rel'])?$_POST['rel']:0;
$space=isset($_POST['space'])?$_POST['space']:0;
$price=isset($_POST['price'])?$_POST['price']:0;
$qual=isset($_POST['qual'])?$_POST['qual']:0;
$user=isset($_POST['user'])?$_POST['user']:0;
if($id!=0){
$q= mysql_query("insert into reviews values(null,$id,'$title','$review','$name','$url','$location', $tech,$cust,$sw,$traf,$rel,$space,$price,$qual,$user,$site_approve,CURDATE())");
if(!$q) echo mysql_error();
$rate=($tech+$cust+$sw+$traf+$rel+$space+$price+$qual+$user)/9; $q=mysql_query("select rate from hostings where hostid=$id");
mysql_fetch_assoc($q); $orate=$q['rate'];
$rate=($rate+$orate)/2;
mysql_query("update hostings set rate=$rate where hostid=$id");
if ($site_approve==1){?>
<div class="trew">Thanks you. Your review has been submited and approved</div>
<?php }else{?> <div class="trew">Thanks you. Your review has been submited and waiting for approvel</div>