문제

I have a form with checkboxes that posts data to the url for next page. I know this is not secure and is not being used in any project. This is only for learning purposes only.

I'm pushing tasks which are pulled from my database.

My url looks like this:

submitted.php?id=?12345

Depending on how many of the task checkboxes I check, I need it to push the IDs to next page.

here is my form:

<form action="Billing.php?id=<?PHP echo $customerid;?>" method="post">
        <?php $query = "SELECT * FROM Service"; 
               $result = mysqli_query($con,$query); 
               while ($line = mysqli_fetch_array($result, MYSQL_ASSOC)) { ?> 
               <input type="checkbox" name="service" value="<?php echo $line['Service_ID']?>"><?php echo $line['Service_Type']?> <br> <?php } ?> 



        <input type="submit" name="next" value="Check Out" style="bottom:3%;Right:3%;position:absolute;background-color:#B2B2B2;font-weight:bold;border-style:double;border-color:black;float:right;" >
    </form>
    </div><!--serviclist-->
    <div id="cust">
            <h3>Customer Information</h3>
            <table style="left: 7%;right: 5%;top: 20%;position: absolute;">
                <tr>
                    <td>Name:<input class="rightText" name="customername" type="text" value="<?PHP echo $name; ?> "></td>
                </tr>
                <tr>
                    <td>Make: <input name="make" type="text" value="<?PHP echo $make; ?>"></td><td>Model: <input class="rightText" name="model" type="text" value="<?PHP echo $model; ?>"></td>
                </tr>
                <tr>
                    <td>Color: <input name="color" type="text" value="<?PHP echo $color; ?>" ></td><td>VIN: <br><input class="rightText" name="VIN" type="text" value="<?PHP echo $vin; ?>" ></td>
                </tr>
            </table>

basically im trying to get it to post my customer id and my services that were checked to next page.

도움이 되었습니까?

해결책

I don't know how you managed to end with this query string, but let's assume you have:

index.php?asd=1&asd=2&asd=3

The you can catch it via

var_dump($_SERVER['QUERY_STRING']);

Output string 'asd=1&asd=2&asd=3' (length=17)

Then split it by & delimiter

var_dump(explode('&', $_SERVER['QUERY_STRING']));

Output:

array (size=3)
0 => string 'asd=1' (length=5)
1 => string 'asd=2' (length=5)
2 => string 'asd=3' (length=5)

Then split by = to find key=>value pairs.

However, this approach I find very unattractive and inefficient.

If you have control over the checkbox names, then build the query string like:

index.php?asd[]=1&asd[]=2&asd[]=3

Then

var_dump($_GET['asd']);

will return array

array (size=3)
0 => string '1' (length=1)
1 => string '2' (length=1)
2 => string '3' (length=1)

다른 팁

You wrote your url wrong, it should look like :

submitted.php?taskid[]=1&taskid[]=7

put checkbox as an ARRAY, example
input type="checkbox" name="taskid[]" value="any value you like"

and in server side php, use a FOR-EACH LOOP to fetch all taskids

    <?php
$tasks = $_GET['taskid'];  
     foreach($tasks as $values)  
       {  
        // do your operations here  
          echo $values;  
         }  
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top