Visualizzazione dei risultati da 1 a 2 su 2

Discussione: redirect con last ID

  1. #1

    redirect con last ID

    Ciao

    non riesco a modificare questo header in modo che dopo l'inserimento mi mandi alla pagina "pippo.php" passando l'ID inserito...consigli ?

    <?php require_once('Connections/conn_dbauto.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 = $HTTP_SERVER_VARS['PHP_SELF'];
    if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
    }

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    $newArr = implode(", ",$_POST['Optional']);
    $insertSQL = sprintf("INSERT INTO macchine (ID_car, `Data`, Targa, Marca_, Modello, TipoAuto_, Colore, Alimentazione_, Cilindrata, Mese, Anno, KmPercorsi, nuovo, Descizione, Optional, Prezzo, PrezzoAcquisto, CommentiInterni, Icona, FOTO1, FOTO2, FOTO3, FOTO4, PROMOTE, Pubblica, Nome_Cognome, Telefono, mail) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
    GetSQLValueString($_POST['ID_car'], "int"),
    GetSQLValueString($_POST['Data'], "date"),
    GetSQLValueString($_POST['Targa'], "text"),
    GetSQLValueString($_POST['Marca_'], "int"),
    GetSQLValueString($_POST['Modello'], "text"),
    GetSQLValueString($_POST['TipoAuto_'], "int"),
    GetSQLValueString($_POST['Colore'], "text"),
    GetSQLValueString($_POST['Alimentazione_'], "int"),
    GetSQLValueString($_POST['Cilindrata'], "int"),
    GetSQLValueString($_POST['Mese'], "int"),
    GetSQLValueString($_POST['Anno'], "int"),
    GetSQLValueString($_POST['KmPercorsi'], "int"),
    GetSQLValueString($_POST['nuovo'], "text"),
    GetSQLValueString($_POST['Descizione'], "text"),
    GetSQLValueString($newArr, "text"),
    GetSQLValueString($_POST['Prezzo'], "int"),
    GetSQLValueString($_POST['PrezzoAcquisto'], "int"),
    GetSQLValueString($_POST['CommentiInterni'], "text"),
    GetSQLValueString($_POST['Icona'], "text"),
    GetSQLValueString($_POST['FOTO1'], "text"),
    GetSQLValueString($_POST['FOTO2'], "text"),
    GetSQLValueString($_POST['FOTO3'], "text"),
    GetSQLValueString($_POST['FOTO4'], "text"),
    GetSQLValueString($_POST['PROMOTE'], "int"),
    GetSQLValueString($_POST['Pubblica'], "text"),
    GetSQLValueString($_POST['Nome_Cognome'], "text"),
    GetSQLValueString($_POST['Telefono'], "text"),
    GetSQLValueString($_POST['mail'], "text"));

    mysql_select_db($database_conn_dbauto, $conn_dbauto);
    $Result1 = mysql_query($insertSQL, $conn_dbauto) or die(mysql_error());
    }

    mysql_select_db($database_conn_dbauto, $conn_dbauto);
    $query_query_marche = "SELECT * FROM marche";
    $query_marche = mysql_query($query_query_marche, $conn_dbauto) or die(mysql_error());
    $row_query_marche = mysql_fetch_assoc($query_marche);
    $totalRows_query_marche = mysql_num_rows($query_marche);

    mysql_select_db($database_conn_dbauto, $conn_dbauto);
    $query_query_alimentazione = "SELECT * FROM alimentazione";
    $query_alimentazione = mysql_query($query_query_alimentazione, $conn_dbauto) or die(mysql_error());
    $row_query_alimentazione = mysql_fetch_assoc($query_alimentazione);
    $totalRows_query_alimentazione = mysql_num_rows($query_alimentazione);

    mysql_select_db($database_conn_dbauto, $conn_dbauto);
    $query_query_tipoauto = "SELECT * FROM tipoauto";
    $query_tipoauto = mysql_query($query_query_tipoauto, $conn_dbauto) or die(mysql_error());
    $row_query_tipoauto = mysql_fetch_assoc($query_tipoauto);
    $totalRows_query_tipoauto = mysql_num_rows($query_tipoauto);
    ?>

  2. #2
    Utente di HTML.it
    Registrato dal
    Mar 2004
    Messaggi
    1,141
    per recuperare l'id dell'ultimo record inserito puoi utilizzare mysql_insert_id():
    http://it.php.net/manual/it/function...-insert-id.php

    e poi fai il reindirizzamento, ex:
    Codice PHP:
    header("Location: pagina.php?id=".mysql_insert_id());
    exit(); 
    //per nn eseguire le altre righe di codice 
    (occhio a non mettere output prima di header("...") se no da errore...)

    ciao

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.