Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2006
    Messaggi
    77

    controllo dati esistenti prima di insert

    <?php require_once('Connections/camere.php'); ?>
    <?php
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 stato_pren (numero_camere, cognome, nome, indirizzo, telefono, fax, email, data_prenotazione, data_arrivo, data_partenza, stato) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
    GetSQLValueString($_POST['numero_camere'], "text"),
    GetSQLValueString($_POST['cognome'], "text"),
    GetSQLValueString($_POST['nome'], "text"),
    GetSQLValueString($_POST['indirizzo'], "text"),
    GetSQLValueString($_POST['telefono'], "text"),
    GetSQLValueString($_POST['fax'], "text"),
    GetSQLValueString($_POST['email'], "text"),
    GetSQLValueString($_POST['data_prenotazione'], "date"),
    GetSQLValueString($_POST['data_arrivo'], "date"),
    GetSQLValueString($_POST['data_partenza'], "date"),
    GetSQLValueString($_POST['stato'], "text"));

    mysql_select_db($database_camere, $camere);
    $Result1 = mysql_query($insertSQL, $camere) or die(mysql_error());
    $insertGoTo = "cercastatopren.php";
    if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s", $insertGoTo));
    }
    mysql_select_db($database_camere, $camere);
    $query_Recordset1 = "SELECT * FROM stato_pren WHERE stato_pren.data_arrivo<='$data_partenza' AND stato_pren.data_partenza>='$data_arrivo'";
    $Recordset1 = mysql_query($query_Recordset1, $camere) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    ?>

    Vorrei aggiungere un cotrollo di inserimento,se la camera 1 con la data_arrivo e la data_partenza gia esiste mi deve dare camera gia prenotata,ma non so dove inserire questo controllo.
    grazie
    ciao

  2. #2
    Utente di HTML.it L'avatar di deleted_id_48586
    Registrato dal
    Nov 2002
    Messaggi
    1,732
    Quando fai il submit dei dati utilizza quelli che hai elencato (camera, data arrivo, data partenza) per una select a DB.
    Se trova un record, quindi la camera è prenotata, generi un avviso e non esegui l'insert altrimenti inserisci i dati tranquillamente.

    Dovrebbe funzionare.

    Ciao.

  3. #3
    Utente di HTML.it
    Registrato dal
    Mar 2006
    Messaggi
    77
    ok grazie ora provo
    ti faro' sapere
    ciao

  4. #4
    Utente di HTML.it
    Registrato dal
    Mar 2006
    Messaggi
    77
    Risolto

    Sgurbat il controllo l'ho messo all'inizio,non so se sul pulsante avrebbe funzionato
    cmq ciao e grazie

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.