Hi.
I am trying to create a form to update multiple entries in a mysql databse. This code below is rough, but it is working to the point wher it pulls the data, displays it in the text areas (but it does not go past the first white space in displaying, that needs to be fixed), and then I can alter the text fields, check a box, and hit submit, and it will update the fields, but the new value is size=20. I also can't update more than one record at a time, which defeats the purpose. Any ideas? Thanks
<html>
<head>
<title>Update rows in database table</title>
</head>
<body>
<?
$host = "localhost"; //database host
$user = "myid"; //database user
$password = "mypw"; //database password
$database = "dbname"; //name of database
$table = "catalog"; //name of table
$columns = "catalog,Name,StreetAddress,City,Country";
$unique_column = "catalog";
$link_id = mysql_connect($host,$user,$password) or die("Cannot connect to database");
$db = mysql_select_db($database) or die("Cannot select database");
if(isset($HTTP_POST_VARS[update]))
{
if(count($update_id) > 0)
{
$update_rows = implode(",",$update_id);
$query = "UPDATE $table SET Name='$Name' , StreetAddress='$StreetAddress' , City='$City' , Country='$Country' WHERE $unique_column=($update_rows)";
$result = mysql_query($query) or die("Error in Query: >>>$query<<<. Error: " . mysql_error());
$affected = mysql_affected_rows();
$count = count($update_id);
$msg = "$affected / $count rows updated";
}
else
{
$msg = "No rows selected for deletion";
}
}
$i = explode(",",$columns);
$num_columns = count($i);
echo "<form method='post' action='$PHP_SELF'>\n";
echo "<table border='1' cellpadding='1' cellspacing='1'>\n";
if(isset($msg))
{
echo "<tr><td align='center' colspan='" . ($num_columns+1) . "'><i>$msg</i></td></tr>\n";
}
echo "<tr>\n";
echo "<td align='center'><b>update?</b></td>\n";
for($x=0;$x<$num_columns;$x++)
{
echo "<td align='center'><b>" . $i[$x] . "</b></td>\n";
}
echo "</tr>\n";
$query = "SELECT $columns FROM $table";
$result = mysql_query($query) or die("Error in Query >>>$query<<<. Error: " . mysql_error());
if($row = mysql_fetch_array($result))
{
do{
echo "<tr>\n";
echo "<td><input type=checkbox name=update_id[] value='" . $row[$unique_column] . "'></td>\n";
for($x=0;$x<$num_columns;$x++)
{
echo "<td><input type=text name=w value=$row[$x] size=20>" . $row[$x] . "</td>\n";
}
echo "</tr>\n";
}while($row = mysql_fetch_array($result));
echo "<tr><td align='center' colspan='" . ($num_columns + 1) . "'><input type='submit' name='update' value='update selected rows!!'></td></tr>\n";
}
else
{
echo "<tr><td align='center' colspan='" . ($num_columns + 1) . "'>No rows in database</td></tr>\n";
}
echo "</table>\n";
echo "</form>\n";
?>
</body>
</html>