Jump to content

Checkbox


dudejma

Recommended Posts

I have a form but it only works for one row at a time. Is there a way I can get it to work for each one checked instead of just the first one checked?

 

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

$row = mysql_fetch_array($result);

$id = $_POST['id'];

$pilotid = $row['pilotID'];

$sql2 = "SELECT hours FROM users WHERE pilotID = '$pilotid'";

$result2 = mysql_query($sql2);

$oldHours = mysql_result($result2, 0);

$newHours = $oldHours + $row['flightTime'];

$arrival = $row['arrival'];

$sql3 = "UPDATE users SET hours = '$newHours', virtualLocation = '$arrival' WHERE pilotID = '$pilotid'";

$result3 = mysql_query($sql3);

$sql4 = "UPDATE pireps SET status = '1' WHERE id = '$id'";

$result4 = mysql_query($sql4)
or die("An error has occured. Please contact the webmaster with the following error: " . mysql_error());

header("Location: pireps.php");
} elseif (isset($_POST['decline'])) {

$row = mysql_fetch_array($result);

$id = $_POST['id'];

$sql2 = "UPDATE pireps SET status = '2' WHERE id = '$id'";

$result2 = mysql_query($sql2)
or die("An error has occured. Please contact the webmaster with the following error: " . mysql_error());

header("Location: pireps.php");
} else {}

Link to comment
https://forums.phpfreaks.com/topic/244550-checkbox/
Share on other sites

You can set checkbox names to something like:

 

<input type="checkbox" name="id[]" value="<?php echo $id; ?>" />

 

That way multiple checkboxes can be submitted as an array to PHP. You can then implode it with a comma as a delimiter and use MySQLs IN function.

Link to comment
https://forums.phpfreaks.com/topic/244550-checkbox/#findComment-1256303
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.