I have an html table with two rows, and four columns. First row is not editable, but the cells in the second row are editable. What I need is to find a way to send the updated cell information to another php file. So far I've been using $_GET['foo'];
and it was working. Until now.
while($row = mysql_fetch_assoc($result)) {
echo "<TR>";
foreach ($row as $cname => $cvalue) {
echo "<TD input type=\"text\" name=\"$cname\" contenteditable=\"true\" ALIGN = \"center\"> $cvalue </TD>";
}
echo "</TR>";
}
In the other php file, I can't seem to get the new data with $_GET
. Any ideas? I'm going to use the new data to update a row in my database with a MySQL Query.
Here's the whole form.
<form action="edit_record_result_final.php" method="get">
<div style="text-align:center">
<?php
$typeName = $_GET["typeName"];
$keyValue = $_GET["keyValue"];
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
if (!mysql_select_db('cmpe')) {
die('Could not select database: ' . mysql_error());
}
$sql="SELECT DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = 'cmpe'
AND table_name = '$typeName'";
$sql2="SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = 'cmpe'
AND table_name = '$typeName'";
$result = mysql_query($sql);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
die($message);
}
$keyType = mysql_result($result, 0);
$result = mysql_query($sql2);
$fieldNum = mysql_result($result, 0);
$sql="SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'cmpe'
AND TABLE_NAME ='$typeName'";
$result = mysql_query($sql);
$header = "";
echo "<TABLE align=\"center\" BORDER=\"15\" CELLSPACING=\"2\" CELLPADDING=\"4\">";
echo "<caption> $typeName </caption>";
echo "<TR>";
for($i = 0; $i<$fieldNum; $i++){
$header = mysql_result($result, $i);
echo "<TD ALIGN = \"center\"><b> $header </b> </TD>";
}
echo "</TR>";
$sql="SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'cmpe'
AND TABLE_NAME ='$typeName'";
$result = mysql_query($sql);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
die($message);
}
$keyName = mysql_result($result, 0);
if(strcmp($keyType, "varchar")==0) {
$sql = "SELECT * FROM $typeName
WHERE $keyName LIKE '$keyValue' ";
}elseif(strcmp($keyType, "int")==0) {
$sql = "SELECT * FROM $typeName
WHERE $keyName = $keyValue";
}else{
$sql = "SELECT * FROM $typeName
WHERE $keyName = '$keyValue' ";
}
$result = mysql_query($sql);
if (!$result) {
die('Could not query:' . mysql_error());
}else{
while($row = mysql_fetch_assoc($result)) {
echo "<TR>";
foreach ($row as $cname => $cvalue) {
echo "<TD input type=\"text\" name=\"$cname\" contenteditable=\"true\" ALIGN = \"center\"> $cvalue </TD>";
}
echo "</TR>";
}
}
echo "</TABLE>";
?>
<p><input type="submit" /></p>
</div>