0

I'm struggling to send multiple records of user to my mysql databse. I'm trying to create a small registration app where users pick events and how many people they want to register on it.

Then i return specific number of registration forms depending on the users pick. Next i want send all this data to my table.

Here is my code so far

if (isset($_POST['submit'])) {

$persons = $_POST['person_number'];
$event = $_POST['event'];

for ($i=1; $i <= $persons; $i++) {
    echo "<b>Uczestnik #" . $i;
    $content = "<form action='thankyou.php' method='post' />";
    $content .= "<div class='form-group'>
    <label for='Imię'>Imię</label>
    <input type='text' class='form-control' name='name' />
    </div>";
    $content .= "<div class='form-group'>
    <label for='Nazwisko'>Nazwisko</label>
    <input type='text' class='form-control' name='last-name' />
    </div>";
    $content .= "<div class='form-group'>
    <label for='email'>Adres Email</label>
    <input type='email' class='form-control' name='email' />
    </div>";

    echo $content;

     }
    echo "<button type='submit' class='btn btn-primary' name='submit2>Rejsestruje się</button>";
    echo "</form>";
}
?>

Also i have another question ,since my users pick few events i store their pick and array and later on post it to form page. How can i separate it and give as input to table query so for example 10 users could go to room a and 20 to room b ?

                <input type="checkbox" class="ck" name="event[]" id="event" value="<?php echo $row['name'];?>"><span>Wybierz</span>

Thank you fo much for all your support

1 Answer 1

3

Answer Of first Question:-

//In Thankyou.php Please write These code of lines

$flag = 0;
if (isset($_POST['submit2'])) {
  if(count($_POST['name']) > 0) {  
    for($k=0;$k<=count($_POST['name']);$k++) {
        if(!empty($_POST['name'][$k])) {
            $insert = "insert into users set
                       name = '".$_POST['name'][$k]."',
                       last_name = '".$_POST['last_name'][$k]."',
                       email = '".$_POST['email'][$k]."'";
             mysql_query($insert);
            $flag++;
        } 

     }    
  } 
   echo "Total number of persons has been inserted is : ". $flag;
   exit;
}



//Main Page Content
if (isset($_POST['submit'])) {
$persons = $_POST['person_number'];
$event = $_POST['event'];
$content = "<form  method='post' />";
for ($i=1; $i <= $persons; $i++) {
    $content .= "<div><b>Uczestnik #" . $i.'</div>';    
    $content .= "<div class='form-group'>
    <label for='Imię'>Imię</label>
    <input type='text' class='form-control' name='name[]' />
    </div>";
    $content .= "<div class='form-group'>
    <label for='Nazwisko'>Nazwisko</label>
    <input type='text' class='form-control' name='last_name[]' />
    </div>";
    $content .= "<div class='form-group'>
    <label for='email'>Adres Email</label>
    <input type='email' class='form-control' name='email[]' />
    </div>";  
    $content .="<br>";
     }  

     $content .="<input type='submit' class='btn btn-primary' name='submit2' value='Rejsestruje się'>";
     $content .="</form>";
     echo $content;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.