Forum Moderators: coopster
<form action="update5.php" method="post">
<table id="form">
<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("hustlersls_co_u", $con);
$result = mysql_query("SELECT * FROM Sky_Points");
echo "<table border=1>";
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td align="center"><input type="text" name="Username[]" value="<?php echo $row['Username'] ?>" ></td>
<td align="center"><input type="text" name="Points[]" value="<?php echo $row['Points'] ?>" ></td>
<td align="center"><input type="text" name="PointsSinceLastPayOut[]" value="<?php echo $row['PointsSinceLastPayOut'] ?>" ></td>
<td align="center"><input type="text" name="DateofLastRun[]" value="<?php echo $row['DateofLastRun'] ?>" ></td>
</tr>
<?php
}
?>
<?php
mysql_close($con);
?>
<tr>
<td align="center" colspan="4"><br/><input name="submit" type="submit" value="Submit"> <input name="reset" type="reset" value="Reset"></td>
</tr>
</table>
</form>
<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("hustlersls_co_u", $con);
$Points = $_POST['Points'];
$PointsSinceLastPayOut = $_POST['PointsSinceLastPayOut'];
$DateofLastRun = $_POST['DateofLastRun'];
foreach ($_POST['Username'] as $username)
{
$query = "UPDATE Sky_Points SET Points = '$Points', PointsSinceLastPayOut = '$PointsSinceLastPayOut', DateofLastRun ='$DateofLastRun' WHERE Username = '$username'" ;
mysql_query($query, $con) or die(mysql_error());
}
if (!mysql_query($query,$con)){
die('Error: '. mysql_error());
}
echo "Points have been updated<br />";
echo "<a href='update_multiple5.php'>Return to update table</a>";
mysql_close($con);
?>
[edited by: Balakir at 12:09 pm (utc) on Apr 1, 2010]
echo $js;
$js_i .= "\n" . 'document.getElementById("' . $username . '_Check").checked = false;';
$js_e .= "\n" . 'document.getElementById("' . $username . '_Check").checked = true;';
}
$js .= $js_i . "\n" . '} else {' . $js_e . "\n" . '}
</script>';
echo $js;
?>
<head>
<?php
echo $js;
?>
</head>
[edited by: Matthew1980 at 10:03 pm (utc) on Apr 5, 2010]
<?php
session_start();
include "db_connect.php";
if($_SESSION['id'])
{
$datesql = "SELECT date FROM event_date_store WHERE eventname = 'Sky'";
$datequery = mysql_query($datesql);
$daterows = mysql_num_rows($datequery);
for($i = 0; $i < $daterows; $i++) {
$formtable1 = '<form action="skypointsupdate.php" method="post" onKeyPress="return event.keyCode!=13" onSubmit="return confirm_entry();"><table id="form" cellspacing="2" align="center">
<tr>
<th style="text-align: center;">Date of Last Run<th>
<td style="text-align: center;"><input type="text" name="date" value="' . mysql_result($datequery, $i, "date") . '" /></td>
</tr>';
}
$formtable1 .= "\n" . '</table>';
$sql = 'SELECT Username, Points, PointsSinceLastPayOut, DateofLastRun FROM Sky_Points ORDER BY Username ASC';
$result = mysql_query($sql);
$rows = mysql_num_rows($result);
$formtable .= '<form name="frm1" action="skypointsupdate.php" method="post" onKeyPress="return event.keyCode!=13" onSubmit="return confirm_entry();"><table id="form" cellspacing="2" align="center">
<tr>
<td style="text-align: center;"><input type="checkbox" name="control_box" onclick="chek_all()" /></td>
<th style="text-align: center;">Username</th>
<th style="text-align: center;">Points</th>
<th style="text-align: center;">Points since<p>last pay out</p></th>
<th style="text-align: center;">Date of last<p>run attended</p></th>
</tr>';
$js = '<script type="text/javascript">
function chek_all() {
var control = document.getElementById("control_box").checked;
if(control) {';
$js_i = '';
$js_e = '';
for($i = 0; $i < $rows; $i++) {
$username = mysql_result($result, $i, "Username");
$formtable .= "\n" . '<tr>
<td style="text-align: center;" ><input type="checkbox" id="' . $username . '_Check" name="' . $username . '_Check" value="1" /></td>
<td style="text-align: center;">' . ucfirst($username) . '</td>
<td style="text-align: center;"><input type="text" name="' . $username . '_Points" value="' . mysql_result($result, $i, "Points") . '" /></td>
<td style="text-align: center;"><input type="text" name="' . $username . '_PointsSinceLastPayOut" value="' . mysql_result($result, $i, "PointsSinceLastPayOut") . '" /></td>
<td style="text-align: center;"><input type="text" name="' . $username . '_DateofLastRun" value="' . mysql_result($result, $i, "DateofLastRun") . '" /></td>
</tr>';
$js_i .= "\n" . 'document.getElementById("' . $username . '_Check").checked = false;';
$js_e .= "\n" . 'document.getElementById("' . $username . '_Check").checked = true;';
}
$js .= $js_i . "\n" . '} else {' . $js_e . "\n" . '}
</script>';
echo $js;
$formtable .= "\n" . '<tr>
<td style="text-align: center;"><input type="checkbox" name="control_box" onclick="chek_all()" /></td>
<td style="text-align: center;" colspan="5"><input name="submit" type="submit" value="Save Changes"> <input name="reset" type="reset" value="Reset Changes"></td>
</tr>';
$formtable .= "\n" . '</table>';
echo "<h1 style='text-align: center;'>Update Sky Points</h1>";
echo $formtable1;
echo $formtable;
}
else
{
echo "You don't belong here!";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update Sky Points</title>
<script language="JavaScript">
function confirm_entry()
{
var agree=confirm("Are you sure you wish to update the points?");
if (agree){
// when ok is pressed the form is submitted
return true;
}else{
// when cancel is pressed nothing happens
return false;
}
}
</script>
<?php echo $js; ?>
</head>
<body>
</body>
</html>
<input type="checkbox" name="control_box" onclick="chek_all()" />
<input type="checkbox" id="control_box" name="control_box" onclick="chek_all()" />
$js_i .= "\n" . 'document.getElementById("' . $username . '_Check").checked = false;';
$js_e .= "\n" . 'document.getElementById("' . $username . '_Check").checked = true;';