I have a HTML/PHP(MySql) related question
I just have troubles finding out how to pass more than one array to the same row in a database
Code: (- at the start of the page)
<?php
if ( isset($_POST['logActivity']) ) {
$date = trim($_POST['date']);
$date = strip_tags($date);
$date = htmlspecialchars($date); //Aquiring a date() function variable
foreach ($_POST['activity'] as $activity => $value){
$query="INSERT INTO monitorlog(dateofentry,activity)
VALUES ('$date','$value')";
mysqli_query($conn,$query);
}} ?>
(In the < body> section)
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" >
<table>
<tr>
<td width='100px' align='center'><input width='100%' value='" . $activity . "' name='activity[]' type='text' class='form-control' /></td><td>
<input width='100%' value='" . $activity2 . "' name='activity2[]' type='number' class='form-control' /></td>
</tr><tr>
<td width='100px' align='center'><input width='100%' value='" . $activity . "' name='activity[]' type='text' class='form-control' /></td><td>
<input width='100%' value='" . $activity2 . "' name='activity2[]' type='number' class='form-control' /></td>
</tr><tr>
<td width='100px' align='center'><input width='100%' value='" . $activity . "' name='activity[]' type='text' class='form-control' /></td><td>
<input width='100%' value='" . $activity2 . "' name='activity2[]' type='number' class='form-control' /></td>
</tr><tr><td>
<button type='submit' class='mybuttons' name='button'>Log to database</button>
</td></tr>
</table>
</form>
The code above successfully inputs the data of $activity
in the database but it also limits the value of the input to $activity's value on that particular row in the database, whereas I need to pass both activity and activity2 to the same row.
Feels like I've tried everything by now to no effect. Hope you guys can help me
Best regards.