yzerman Posted February 3, 2007 Share Posted February 3, 2007 ok, I messed this up somewhere. Here is the code in action: http://www.sandynpaul.com/cal/bancompare2.php Here is what I want to do. When 1 of the check boxes is checked, I want that(those) record(s) in the database to update. The problem is, when I use $row[0] in the query, it selects random records to update (at least it looks random to me) Here is the code for the script: <?PHP //mysql info $dbuser = "me"; $dbpass = "mypass"; $dbname = "mydatabase"; mysql_connect(localhost,$dbuser,$dbpass); @mysql_select_db($dbname) or die("Unable to select database"); //here is the query $query = "SELECT `GUID`.`BannedGUID`, `GUID`.`banned` FROM GUID, GUID2 WHERE ( `GUID2`.`CALGUID` = `GUID`.`BannedGUID` )"; $result = mysql_query($query); if ($result) { echo '<table><tr><td><b><u>GUID</u></b></td><td><b><u>Profile</u></b></td><td><b><u>CAL Account</u></b></td><td><b><u>Ban Reason</u></b></td><td><b><u>CAL Banned</u></b></td></tr>'; while ($row = mysql_fetch_array($result)) { if ($row[1] == '1') { $banned = '<font color="red">YES</font>'; } elseif ($row[1] == '0') { $banned = "<form action=\"$_SERVER[php_SELF]\" method=\"post\"><input type=\"checkbox\" name=\"ban\" />"; } echo '<tr><td>', $row[0], '</td><td><a href="http://caleague.com/?page=history&type=roster&uniqueid=', $row[0], '" target="_blank">Profile</a></td><td><a href="https://backoffice.caleague.com/?page=usearch&method=3&by=uniqueid&for=', $row[0],'" target="_blank">Linked Accounts</a> (Backoffice)<td><a href="http://pbbans.fbi-clan.org/index.php?type=guid&find=', $row[0], '" target="_blank">Ban Reason</a></td><td>', $banned, '</td></tr>'; if (isset($_POST['submit'])) { if ($ban == "on") { $query2 = "UPDATE GUID SET banned = 1 WHERE BannedGUID = $row[0]"; $result2 = mysql_query($query2); } } } echo '</table><br /><input name="submit" type="submit" value="Update" />'; } else { echo 'An error has occured, please try again'; } ?> Quote Link to comment Share on other sites More sharing options...
simcoweb Posted February 3, 2007 Share Posted February 3, 2007 What do you want your data to look like in the database? In other words, say they select all the checkboxes. Do you want the database field to contain all the choices? Or, do you perhaps want each choice to occupy its own field? Quote Link to comment Share on other sites More sharing options...
yzerman Posted February 3, 2007 Author Share Posted February 3, 2007 the data currently looks like this: BannedGUID | banned ------------|-------- 12345 | 0 67890 | 1 23456 | 0 if banned = 0, and he is banned, I want the user to be able to check the checkbox for 12345 hit update, and update that record, without updating 23456 Quote Link to comment Share on other sites More sharing options...
simcoweb Posted February 3, 2007 Share Posted February 3, 2007 Ok, then perhaps instead of creating an array with the checkboxes you may consider having each one as a separate form field. Example: <input type="checkbox" name="banned1" value="1"> <input type="checkbox" name="banned2" value="1"> <input type="checkbox" name="banned3" value="1"> This way you can set a separate variable for each field and whichever one is selected would be inserted into the database. Quote Link to comment Share on other sites More sharing options...
yzerman Posted February 3, 2007 Author Share Posted February 3, 2007 The checkboxes are created dynamically from over 20,000 records. The idea you just posted is just not feasable. Quote Link to comment Share on other sites More sharing options...
yzerman Posted February 3, 2007 Author Share Posted February 3, 2007 Finally got it to work, here is the working code. <?PHP //mysql info $dbuser = "me"; $dbpass = "mypass"; $dbname = "mydatabase"; mysql_connect(localhost,$dbuser,$dbpass); @mysql_select_db($dbname) or die("Unable to select database"); //form submittal if (isset($_POST['submit'])) { foreach ($Selected as $s) { $query2 = "UPDATE GUID SET banned = 1 WHERE BannedGUID = '$s'"; $result2 = mysql_query($query2); if (!$result2) { die('Invalid query: ' . mysql_error()); } } } //here is the query $query = "SELECT `GUID`.`BannedGUID`, `GUID`.`banned` FROM GUID, GUID2 WHERE ( `GUID2`.`CALGUID` = `GUID`.`BannedGUID` )"; $result = mysql_query($query); if ($result) { echo '<table><tr><td><b><u>GUID</u></b></td><td><b><u>Profile</u></b></td><td><b><u>CAL Account</u></b></td><td><b><u>Ban Reason</u></b></td><td><b><u>CAL Banned</u></b></td></tr>'; while ($row = mysql_fetch_array($result)) { if ($row[1] == '1') { $banned = '<font color="red">YES</font>'; } elseif ($row[1] == '0') { $banned = "<form action=\"$_SERVER[php_SELF]\" method=\"post\"><input type=\"checkbox\" name=\"Selected[]\" value=\"$row[0]\" />"; } echo '<tr><td>', $row[0], '</td><td><a href="http://caleague.com/?page=history&type=roster&uniqueid=', $row[0], '" target="_blank">Profile</a></td><td><a href="https://backoffice.caleague.com/?page=usearch&method=3&by=uniqueid&for=', $row[0],'" target="_blank">Linked Accounts</a> (Backoffice)<td><a href="http://pbbans.fbi-clan.org/index.php?type=guid&find=', $row[0], '" target="_blank">Ban Reason</a></td><td>', $banned, '</td></tr>'; } echo '</table><br /><input name="submit" type="submit" value="Update" />'; } else { echo 'An error has occured, please try again'; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.