prent327
08-24-2005, 08:00 PM
I need some help troubleshooting my own code here. This was mostly written by someone else, so I now find myself unable to edit it correctly. The file that I post is the third in a series, the first of which calls up several rows of data for a selected entry, the second which allows the user to edit the data by creating edit boxes for each of those rows, (the column names here are "IDString", "Entry", "1987Q1"....). Now this final file is supposed to make an array of all the previous edited entries and plug them back into the database, but no updates are being made. If anyone can see why, I would love to know what the problem is. Thanks.
<html>
<head>
<title> PSC Data </title>
</head>
<body>
<?php
$db = mysql_connect('host', 'user', 'password');
if(!$db) {
print "Error - cound not connect to server";
exit;
}
$er = mysql_select_db('prent32_FinDat');
if(!$er) {
print "Error - cound not connect to database";
exit;
}
$names = array("IDString", "Data", "1987Q1", "1987Q2", "1987Q3", "1987Q4", "1988Q1", "1988Q2", "1988Q3", "1988Q4", "1989Q1", "1989Q2", "1989Q3", "1989Q4", "1990Q1", "1990Q2", "1990Q3", "1990Q4", "1991Q1", "1991Q2", "1991Q3", "1991Q4", "1992Q1", "1992Q2", "1992Q3", "1992Q4", "1993Q1", "1993Q2", "1993Q3", "1993Q4", "1994Q1", "1994Q2", "1994Q3", "1994Q4", "1995Q1", "1995Q2", "1995Q3", "1995Q4", "1996Q1", "1996Q2", "1996Q3", "1996Q4", "1997Q1", "1997Q2", "1997Q3", "1997Q4", "1998Q1", "1998Q2", "1998Q3", "1998Q4", "1999Q1", "1999Q2", "1999Q3", "1999Q4", "2000Q1", "2000Q2", "2000Q3", "2000Q4", "2001Q1", "2001Q2", "2001Q3", "2001Q4", "2002Q1", "2002Q2", "2002Q3", "2002Q4", "2003Q1", "2003Q2", "2003Q3", "2003Q4", "2004Q1", "2004Q2", "2004Q3", "2004Q4", "2005Q1", "2005Q2");
$numNames = count($names);
$numData = count($_POST);
$count = 0;
$column = 0;
foreach($_POST as $key=>$value) {
if($count >= $numNames) {
$count = 0;
}
$column = $names[$count];
$key = $value;
if($column <> 'IDString') {
$sql = "UPDATE Income SET $column = '$key' WHERE IDString = '$ID'";
$result = mysql_query($sql, $db);
if (!result)
{
die(mysql_error());
}
}
if($column == 'IDString') {
$ID = $key;
}
$count++;
}
header('location:AllIncome.php');
?>
</body>
</html>
<html>
<head>
<title> PSC Data </title>
</head>
<body>
<?php
$db = mysql_connect('host', 'user', 'password');
if(!$db) {
print "Error - cound not connect to server";
exit;
}
$er = mysql_select_db('prent32_FinDat');
if(!$er) {
print "Error - cound not connect to database";
exit;
}
$names = array("IDString", "Data", "1987Q1", "1987Q2", "1987Q3", "1987Q4", "1988Q1", "1988Q2", "1988Q3", "1988Q4", "1989Q1", "1989Q2", "1989Q3", "1989Q4", "1990Q1", "1990Q2", "1990Q3", "1990Q4", "1991Q1", "1991Q2", "1991Q3", "1991Q4", "1992Q1", "1992Q2", "1992Q3", "1992Q4", "1993Q1", "1993Q2", "1993Q3", "1993Q4", "1994Q1", "1994Q2", "1994Q3", "1994Q4", "1995Q1", "1995Q2", "1995Q3", "1995Q4", "1996Q1", "1996Q2", "1996Q3", "1996Q4", "1997Q1", "1997Q2", "1997Q3", "1997Q4", "1998Q1", "1998Q2", "1998Q3", "1998Q4", "1999Q1", "1999Q2", "1999Q3", "1999Q4", "2000Q1", "2000Q2", "2000Q3", "2000Q4", "2001Q1", "2001Q2", "2001Q3", "2001Q4", "2002Q1", "2002Q2", "2002Q3", "2002Q4", "2003Q1", "2003Q2", "2003Q3", "2003Q4", "2004Q1", "2004Q2", "2004Q3", "2004Q4", "2005Q1", "2005Q2");
$numNames = count($names);
$numData = count($_POST);
$count = 0;
$column = 0;
foreach($_POST as $key=>$value) {
if($count >= $numNames) {
$count = 0;
}
$column = $names[$count];
$key = $value;
if($column <> 'IDString') {
$sql = "UPDATE Income SET $column = '$key' WHERE IDString = '$ID'";
$result = mysql_query($sql, $db);
if (!result)
{
die(mysql_error());
}
}
if($column == 'IDString') {
$ID = $key;
}
$count++;
}
header('location:AllIncome.php');
?>
</body>
</html>