php - $_POST on a While loop? -
my question is: can post using form , inside while loop? have supposed give me check box , titles of songs next it, want able select few check boxes , post them "process.php" code made not posting process.php. if click submit button without checking boxes defaults last result # in database, if check or few boxes says "undifined off-set # 9" last result in database. if make form inside while loop ton of submit buttons per result. not sure im doing wrong! please me!!!
this need happen ⎕ song name ⎕ song name 2 submit
if click submit on process.php should able use "song_name"
please select songs: <br> <form method="post" action="process.php"> <?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "song_selection"; // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "select * songs"; $result = $conn->query($sql); if ($result->num_rows > 0) { $a = 1; // output data of each row while($row = $result->fetch_assoc()) { $song_name = $a++; //echo "title: " . $row["title"]. "<br>"; ?> <div width="200"> <label> <input type="checkbox" name="<?php echo $song_name; ?>" value="<?php echo $song_name; ?>" id="checkboxgroup1_0" /> <?php echo $row['title']; ?></label> </div> <?php } echo '<input type="submit" value="thanks">'; } else { echo "0 results"; } ?> </form> <?php echo $_post[$song_name]; ?>
the $song_name
counter value, not actual song name, , used in value=""
attribute. believe $row['title']
actual song name, replace,
<input type="checkbox" name="<?php echo $song_name; ?>" value="<?php echo $song_name; ?>" id="checkboxgroup1_0" />
with
<input type="checkbox" name="<?php echo $song_name; ?>" value="<?php echo $row['title']; ?>" id="checkboxgroup1_0" />
and question:
if click submit on process.php should able use "song_name"
if requirement process form this:
process.php
foreach($_post $key => $value){ echo $key . ": " . $value . "<br />"; }
Comments
Post a Comment