Php Undifend index

Я использовал этот код раньше. Теперь я использовал тот же код для другого скрипта, но теперь я получаю уведомление. Я хочу поместить эту информацию в базу данных, но я получаю неопределенный индекс. Неважно что я делаю.

 <pre><code>
    <?php
    define('DB_NAME', 'videonaardvd');
    define('DB_USER', 'root');
    define('DB_PASSWORD', 'usbw');
    define('DB_HOST', 'localhost');

$Type = $_POST['Type'];
$Aantal = $_POST['Aantal'];
$ExtraKopie = $_POST['ExtraKopie'];
$Naam = $_POST['Naam'];
$Adres = $_POST['Adres'];
$Postcode = $_POST['Postcode'];
$Plaats = $_POST['Plaats'];
$Telefoon = $_POST['Telefoon'];
$Email = $_POST['Email'];
$Datum = $_POST['Datum'];
        $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

        if(!$link){
            die('could not connect:' . mysql_error()); 
            }
        $db_selected = mysql_select_db (DB_NAME, $link);

        if (!$db_selected) {
            die('Can\'t use ' . DB_NAME . ': ' . mysql_error ());
            }

        $sql = "INSERT INTO gegevens (Type,Aantal,ExtraKopie,Naam,Adres,Postcode,Plaats,Telefoon,Email,Datum)  
                VALUES ('$Type','$Aantal','$ExtraKopie','$Naam','$Adres','$Postcode','$Plaats','$Telefoon','$Email','$Datum'";

        if(!mysql_query($sql)){
            die('Er is iets fout gegaan. Probeer het later opnieuw.: '. mysql_error());
            }

?>
Bedankt voor het versturen van je opdracht!!!
<br />
<input class="terug" type=button onClick="location.href='index.html'" value='Terug'>

--------------------------- HTML --------------------- -------------------

<fieldset>
    <div id="type">
        <form><div id="namen"> <h4 class="namen"> Type...........................Aantal...............Extra kopie</h4> </div>
            <input type="text" class="aantal" name="Aantal">    <input type="checkbox" class="extra" name="ExtraKopie">     <input type="checkbox" name="Type" >VH / S-VHS                  <br>
            <input type="text" class="aantal" name="Aantal">    <input type="checkbox" class="extra" name="ExtraKopie">     <input type="checkbox" name="Type">Video2000 / VCC          <br>
            <input type="text" class="aantal" name="Aantal">    <input type="checkbox" class="extra" name="ExtraKopie">     <input type="checkbox" name="Type">Mini DV                   <br>
            <input type="text" class="aantal" name="Aantal">    <input type="checkbox" class="extra" name="ExtraKopie">     <input type="checkbox" name="Type">Video 8, HI8 & Digital 8      <br>
            <input type="text" class="aantal" name="Aantal">    <input type="checkbox" class="extra" name="ExtraKopie">     <input type="checkbox" name="Type">Betamax                  <br>
            <input type="text" class="aantal" name="Aantal">    <input type="checkbox" class="extra" name="ExtraKopie">     <input type="checkbox" name="Type">VHS-C                         <br>
            <input type="text" class="aantal" name="Aantal">    <input type="checkbox" class="extra" name="ExtraKopie">     <input type="checkbox" name="Type">Filmspoelen              <br>
        </form>
    </div>
    <div id="gegevens">
        <form>
            <input type="text" name="Naam" placeholder="De heer/mevrouw"><br>
            <input type="text" name="Adres" placeholder="Adres"><br>
            <input type="text" name="Postcode" placeholder="Postcode">
            <input type="text" name="Plaats" placeholder="Plaats"><br>
            <input type="text" name="Telefoon" placeholder="Telefoon"><br>
            <input type="text" name="Email" placeholder="Email"><br> <br><br>
            <input type="text" name="Datum" placeholder="Datum:"><br>
        </form> 
    </div>
    <input type="submit" href="collect.php" class="versturen">
    </fieldset>

1 ответ

Не пробовал это, поэтому я позволю вам попробовать.

$user = 'root';
$pass = 'usbw';
$dbname = 'videonaardvd';
$host = 'localhost';
$opt = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION );
$dsn = "mysql:host=$host;dbname=$dbname";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
    function died($error){ 
        echo "We are very sorry, but there were error(s) found with the form you submitted. "; 
        echo "These errors appear below.<br /><br />"; 
        echo $error."<br /><br />"; 
        echo "Please go back and fix these errors.<br /><br />"; 
        die();
    }
    if (!$_POST['Type'] || !$_POST['Aantal'] || !$_POST['ExtraKopie'] || !$_POST['Naam'] || !$_POST['Adres'] || !$_POST['Postcode'] || !$_POST['Plaats'] || !$_POST['Telefoon'] || !$_POST['Email'] || !$_POST['Datum']) {
        died('<p>Please remember to supply all of the requested information! You may press your back button to attempt again!</p>');
        exit;
    }
    $Type = $_POST['Type'];
    $Aantal = $_POST['Aantal'];
    $ExtraKopie = $_POST['ExtraKopie'];
    $Naam = $_POST['Naam'];
    $Adres = $_POST['Adres'];
    $Postcode = $_POST['Postcode'];
    $Plaats = $_POST['Plaats'];
    $Telefoon = $_POST['Telefoon'];
    $Email = $_POST['Email'];
    $Datum = $_POST['Datum'];

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    if(!preg_match($email_exp,$Email)){ 
        $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 
    } 
    $string_exp = "/^[A-Za-z .'-]+$/"; 
    if(!preg_match($string_exp,$Naam)){ 
        $error_message .= 'The Name you entered does not appear to be valid.<br />'; 
    }
    if(strlen($error_message) > 0){ 
        died($error_message); 
    }
    else {
        try {        
            $DBH = new PDO($dsn, $user, $pass, $opt);
            $STH = $DBH->prepare("INSERT INTO gegevens (Type,Aantal,ExtraKopie,Naam,Adres,Postcode,Plaats,Telefoon,Email,Datum) VALUES (:Type, :Aantal, :ExtraKopie, :Naam, :Adres, :Postcode, :Plaats, :Telefoon, :Email, :Datum)");
            $STH->bindParam(':Type', $_POST['Type']);
            $STH->bindParam(':Aantal', $_POST['Aantal']);
            $STH->bindParam(':ExtraKopie', $_POST['ExtraKopie']);
            $STH->bindParam(':Naam', $_POST['Naam']);
            $STH->bindParam(':Adres', $_POST['Adres']);
            $STH->bindParam(':Postcode', $_POST['Postcode']);
            $STH->bindParam(':Plaats', $_POST['Plaats']);
            $STH->bindParam(':Telefoon', $_POST['Telefoon']);
            $STH->bindParam(':Email', $_POST['Email']);
            $STH->bindParam(':Datum', $_POST['Datum']);
            $STH->execute();
        } catch (PDOException $e) {
            echo $e->getMessage();
        }
        echo "<p>Submitted!</p>";
    }
}
$DBH = null;
Другие вопросы по тегам