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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.