samedi 21 avril 2018

POST method, echo more than 1 checkbox output

first of all I've been googling about this and found that I need to insert array box inside the checkbox name. I did that but it returned an error. May I knew what I did wrong and how to fix it?

Here's the code that I manage to echo only 1 value although both checkbox are been checked. (Before adding "[]")

<form method="post">
    <div class="form-group">
    <p>If yes, which type of disposable contact lens have you worn before?</p>
    <input type="checkbox" name="disposable_lens"  value="Monthly"/> Monthly<br>
    <input type="checkbox" name="disposable_lens"  value="Daily Disposables"/> Daily Disposables<br>
</div>
</form>

if(empty($_POST["disposable_lens"]))
{
    $error .= '<p><label class="text-danger">Disposable_lens is required</label></p>';
}
else
{
    $disposable_lens = clean_text($_POST["disposable_lens"]);
    echo $disposable_lens."</br>";
}

This is the code after I inserted the "[]" and used foreach statement

<div class="form-group">
    <p>If yes, which type of disposable contact lens have you worn before?</p>
    <input type="checkbox" name="disposable_lens[]"  value="Monthly"/> Monthly<br>
    <input type="checkbox" name="disposable_lens[]"  value="Daily Disposables"/> Daily Disposables<br>
</div>

    if(empty($_POST["disposable_lens"]))
{
    $error .= '<p><label class="text-danger">Disposable_lens is required</label></p>';
}
else
{
    foreach($_POST['disposable_lens'] as $disposable_lens){
        echo $disposable_lens."</br>";
}

I got this error when I go to index.php

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\send_mail\index.php on line 216

And I checked on line 216, there are no any word, just got one ~ (in red) and I cant delete it. This is the image screenshot I took.




Aucun commentaire:

Enregistrer un commentaire