sql - How to pass the value of a dropdownmenu with php to database -


i have following form cannot select (dropdown menu multiple choice) value added in database. wrong? using php , can other value addedd correctly except select part. have dropdown menu choices , when press "submit" selected value database.

            <form  action="post.php" method="post">                              <div class="form-group">                     <label for="name">customer name:</label>                     <input type="text" name="name" class="form-control" id="name">                         </div>                  <div class="form-group">                     <label for="email">email address:</label>                     <input type="email" name="email" class="form-control" id="email">                 </div>                  <div class="form-group">                     <label for="number">mobile number:</label>                     <input type="text" name="number" class="form-control" id="number">                 </div>                  <div class="form-group">                     <label for="price">price:</label>                     <input type="text" name="price" class="form-control" id="price">                 </div>                  <div class="form-group">                     <label for="payment">payment type</label>                     <input type="text" name="payment" class="form-control" id="payment">                 </div>                  <div class="form-group">                     <label for="device">device name:</label>                     <input type="text" name="device" class="form-control" id="device">                 </div>                   <div class="form-group">                     <label for="status">status:</label>              <select name="status[]" multiple class="form-control" id="status"> <option value="new">new</option> <option value="green">progress</option> <option value="blue">wait</option> <option value="pink">done</option> <option value="yellow">close</option> </select>        </div>                               <button type="submit"  name="submit" class="btn btn-default">submit</button> </form> 

and query:

$sql = "insert ... (name, mail, number, device, price, paymenttype,status,date) values ('$name', '$email', '$number', '$device', '$price', '$payment','$status',now())"; if(mysqli_query($link, $sql)){     // echo "records added successfully.";     header("location:....php?message=the customer has been added database");  } else{     echo "error: not able execute $sql. " . mysqli_error($link); } 

you have change following html code:

name="status[]" 

to:

name="status" 

also, based on this should add exit() after redirecting page:

header("location:....php?message=the customer has been added database"); exit(); 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -