Hi,
sorry, I’m pretty new with PHP but I gotta start somewhere, I’m having a problem processing a simple form to update a database.
I want a checkbox to value ‘1’ if it is checked and a value ‘0’ if it is not. I’ve looked at various forums but unable to find a solution that works for me.
the nearest thing I’ve found is using a hidden file with the same name (closed[]) as the checkbox name, but when the form posts
both values are entered and the array goes out of sync.
here is my form page:-
[php]
<?php $page = "test"; @include("admin_head2.php"); @include("../inc/cfd.php"); $cxn = mysqli_connect($host,$username,$password,$db_name) or die ("couldn't connect to Server"); $query = "SELECT * FROM $tbl_open"; $result = mysqli_query($cxn,$query) or die ("couldn't execute query"); $i = 0; ?>ID | Day | Open | Closed | Closed All Day | |||
<? echo $rows['id']; ?> | /> | ||||||
[/php]
and here is the form process page (update_times.php).
[php]<
?php
@include("…/…/inc/cfd.php");
$cxn1 = mysqli_connect($host,$username,$password,$db_name)
or die (“couldn’t connect to Server”);
$size = count($_POST[‘id’]);
$i = 0;
while ($i<$size)
{
$id = $_POST[‘id’][$i];
$day = $_POST[‘day’][$i];
$start = $_POST[‘start’][$i];
$stop = $_POST[‘stop’][$i];
$closed = $_POST[‘closed’][$i];
$query = “UPDATE opentimes SET day = ‘$day’,
start = ‘$start’,
stop = ‘$stop’,
closed = ‘$closed’
WHERE id = ‘$id’ LIMIT 1”;
mysqli_query($cxn1,$query) or die (“Error in query: $query”);
++$i;
}
mysqli_close();
?>[/php]
I seem to keep going round and round in circles. If anyone can help I would really appreciate it.
Many thanks.