hello guys, i'm stuck with some code and i'm getting frustrated that i cannot get it work. Please help :))

I have a database with some details about registered users with a column named Activated (which is 0 or 1). I want to make a page were restricted users can modify this status (Activated) using checkboxes.

<?php
$con = mysql_connect("localhost","root","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("silvermountain", $con);

$result = mysql_query("SELECT * FROM brokeri");

echo "<form method='post' action='activate_account.php'>";
echo "<table border='0' width='100%' class='tabel_administrator' cellspacing='0'>
<tr>
<th>Nume</th>
<th>Prenume</th>
<th>Companie</th>
<th>Adresa companie</th>
<th>Nr Tel</th>
<th>Ap vandute</th>
<th>Ap reservate</th>
<th>Activat</th>

</tr>";
$a=0;
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['nume'] . "</td>";
  echo "<td>" . $row['prenume'] . "</td>";
  echo "<td>" . $row['companie'] . "</td>";
  echo "<td>" . $row['adresa_companie'] . "</td>";
  echo "<td>" . $row['nr_tel'] . "</td>";
  echo "<td>" . $row['apartamente_vandute'] . "</td>";
  echo "<td>" . $row['apartamente_rezervate'] . "</td>";
  if($row['activat'] == 1) echo "<td>Activated</td>";
  else {
	  echo "<td><input type='checkbox' name='to_activate[]' value=". $id[$a] ."></td>";
  		$a++;
	}
  echo "</tr>";
    }
echo "</table>&nbsp;&nbsp;&nbsp;<input type='submit' name='submit' id='submit' value='Update'/></form></br>";


mysql_close($con);
?>

but now i don't know what to write in "activate_account.php" so that i modify only the users that were checked.

Sorry you might need to be a bit more specific.
What is the goal you are trying to accomplich?
Are you going to send an email to them where they click a link and it activates thier account?
Or have a page administrators can view to change the 0 to 1 in an update account form?

... have a page administrators can view to change the 0 to 1 in an update account form?

that is what i am trying to do

<?php require_once(connection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE member SET password=%s WHERE name=%s",
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['name'], "text"));

  mysql_select_db($database_member, $member);
  $Result1 = mysql_query($updateSQL, $member) or die(mysql_error());

  $updateGoTo = "test.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

mysql_select_db($database_member, $member);
$query_Recordset1 = "SELECT * FROM member";
$Recordset1 = mysql_query($query_Recordset1, $member) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<html>
<head>
<title>test</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Password:</td>
      <td><select name="password" id="password">
          <option>&lt;?php echo htmlentities($row_Recordset1['password'], ENT_COMPAT, 'utf-8'); ?&gt;</option>
          <option>1</option>
      </select></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Update record" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1" />
  <input type="hidden" name="name" value="<?php echo $row_Recordset1['name']; ?>" />
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

this is an example i just did in dreamweaver
obviously your changing an id rather than password so change as neccesary

maybe using an input with the type "hidden" that has a value of the user id would help you.

metalix: Who is $database_member and $member ? They are not assigned any value.

solved it, thank you very much

damn, this is working for only one item. But i generate a table with all users from database, and it only modifies the first one. Why is this happening ?

$database_member and $member was my table sorry forgot to change them to $table for you. these are in my include file which you would probably have embeded.
glad to see you solved it.
please mark solved threads as solved thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.