2017-02-21 3 views
1

Ich bekomme einen Fehler, wo es heißt, dass es leer ist. Aber wenn mein Textfeld leer ist, zeigt es keinen Fehler. Ich meine, es leere Felder erlaubt, aber nicht in ausgewählte OptionErlaube keinen ausgewählten Wert zu wählen

Hier ist mein html:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

<form role="form" id="cakechoices" name="cakechoices" method="post"> 

<label for="dedicationT"> Dedication Text: </label> <input type="text" name="dedicationT" id="dedicationT" size="20" placeholder="Dedication" /> 

<label for="service_date"> Date: </label> <input type="date" id="service_date" name="service_date" value="M-D-YY"/> 

<br> <label> Branch: <select name="branch_name" id="branch_selection" /> 
<option disabled selected value>-- Select one --</option> 
<option value="B1">B1 </option> 
<option value="B2">B2 </option> 
<option value="B3">B3 </option> 
<option value="B4">B4 </option> 
</select> </label> 
</br> 

<input type="submit" id="submit" class="btn btn-default" value="Order Now" /> 

</form> 

Hier ist meine php:

<?php 

    $link = mysql_connect('localhost', 'root', ''); 
    if (!$link) { die('Could not connect: ' . mysql_error()); } 
    if (!mysql_select_db('myrnas')) { die('Could not select database: ' . mysql_error()); } 

    session_start(); 
$dedicationT = $_POST['dedicationT']; 
$service_date = $_POST['service_date']; 
$branch_name = $_POST['branch_name']; 

$query1 = "INSERT INTO order_cake (dedicationT, service_date, branch_name) VALUES ('$dedicationT', '$service_date', '$branch_name'); 

if(@mysql_query($query1,$link)) 
    { echo "Done!"; } 
    else { print '<p> <h1> Somethings wrong, failed to connect!!!. GAD WHY!?! </h1> '.mysql_error().'</p>'; } 

?> 

Das ist mein Fehler ist: Undefined index: branch_name in D: \ Xampp \ htdocs \ system \ anpassen \ ordersent.php on line

das ist mein Ajax gleiche in der HTML-Datei

function submit_order($form) { 
    $.ajax({ 
     url : "process/ordersent.php", 
     type : "POST", 
     cache : false, 
     data : $form.serialize(), 
     success: function(response) { 

     alert(response); 
     if(response == "Done") { 
      window.location.href = "home.php"; 
      } 
     } 
    }); 
    } 


     $('#submit').click(function(){ /* when the submit button in the modal is clicked, submit the form */ 
     swal({ 
      title: "Are you sure?", 
      type: "warning", 
      showCancelButton: true, 
      confirmButtonColor: "#ff5c33", 
      confirmButtonText: "Order Now!", 
      closeOnConfirm: false 
     }, 


     function(isConfirm){ 
      if (isConfirm) { 

      submit_order($('#cakechoices')); 
      //swal("Deleted!", "Your imaginary file has been deleted.", "success"); 
      } 
     }); 

     return false; 
     }); 

Hoffnung jemand kann mir helfen!

Antwort

1

Dies ist auf das Attribut "deaktiviert" zurückzuführen. Entfernen Sie es einfach und der Post "Branch_Name" wird mit leerem Wert gesendet.

Sie setzen es als deaktiviert und das Ergebnis ist, dass keine Variable $ _POST ['Branchenname'] überhaupt gesendet wird.

Ändern Sie es an:

<option selected value="">-- Select one --</option> 
+0

ohgad, warum nicht ich es versuchen .. * ewig * versteckt Danke soviel !! – Khyana

+0

Sie sind herzlich willkommen DownCrow. Bitte akzeptieren Sie die Antwort, wenn Sie es für richtig halten –

Verwandte Themen