Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Gestire la data con valore NULL

    Salve,

    Ho un input type text dove dovrei inserire il valore in un capo DATE di sql.

    Quindi dovrei fare un controllo che se il campo data è vuoto deve restituirmi nullo.

    codice:
    if ($_POST["text4"])==0 {$text4 = NULL;} else {$text4 = addslashes(filter_var($_POST['text4'], FILTER_SANITIZE_STRING));}
    		
    if ($_POST["text5"])==0 {$text5 = NULL;} else {$text5 = addslashes(filter_var($_POST['text5'], FILTER_SANITIZE_STRING));}
    		
    if ($_POST["text6"])==0 {$text6 = NULL;} else {$text6 = addslashes(filter_var($_POST['text6'], FILTER_SANITIZE_STRING));}
    Però non funziona, mi sapete dire dove sbaglio?
    No Blitz No Party!

  2. #2
    Utente di HTML.it L'avatar di las
    Registrato dal
    Apr 2002
    Messaggi
    1,221
    se il campo non viene compilato dall'utente e non ha nessun valore di default nella pagina successiva la variabile $_POST corrispondente non esiste, quindi il controllo $_POST["text4"])==0 restituisce falso (perchè una variabile che non esiste non è uguale a 0)

    quindi ti conviene modificare con

    if(empty($_POST["text4"]))

    oppure più semplicemente

    if(!@$_POST["text4"])
    Il calcolatore è straordinariamente veloce, accurato e stupido.
    L'uomo è incredibilmente lento, impreciso e creativo.
    L'insieme dei due costituisce una forza incalcolabile.
    (Albert Einstein)

  3. #3
    Come faccio ad inserire un valore null, io sto facendo cosi :
    codice:
    if(isset($_POST['text4'])&&($_POST['text4']=="")){
    $text4 = NULL;} else {$text4 = addslashes(filter_var($_POST['text4'], FILTER_SANITIZE_STRING));}
    				
    if(isset($_POST['text5'])&&($_POST['text5']=="")){
    $text5 = NULL;} else {$text5 = addslashes(filter_var($_POST['text5'], FILTER_SANITIZE_STRING));}
    		
    if(isset($_POST['text6'])&&($_POST['text6']=="")){
    $text6 = NULL;} else {$text6 = addslashes(filter_var($_POST['text6'], FILTER_SANITIZE_STRING));}
    Ma mi da questo errore :

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',)' at line
    No Blitz No Party!

  4. #4
    Utente di HTML.it L'avatar di bstefano79
    Registrato dal
    Feb 2004
    Messaggi
    2,520
    mancano gli apici
    non
    $text4 = NULL;
    ma
    $text4 = "NULL";

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.