0

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>

arikan
  • 893
  • 9
  • 18
  • 1
    Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and consider using PDO, [it's not as hard as you think](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 14 '15 at 18:50
  • We would have to see the whole form to see what method you're using to send the information. – Jay Blanchard May 14 '15 at 18:53
  • 1
    `` and ``? – Sean May 14 '15 at 18:54
  • @JayBlanchard I added the whole form. – arikan May 14 '15 at 18:58
  • Add error reporting to the top of your file(s) right after your opening ` – Jay Blanchard May 14 '15 at 18:59
  • @JayBlanchard this is the warning/error: **Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\xampp\htdocs\foo\edit_record_result.php on line 13** – arikan May 14 '15 at 19:02
  • And I'm getting Undefined Index Error in my edit_record_result_final.php file. – arikan May 14 '15 at 19:04
  • I didnt think these contenteditable blocks get submitted with the form. Can you use your network debugging bar in your web browser to make sure that data is actually being sent to the server. – Kris Zani May 14 '15 at 19:14
  • @KrisZani You might be right. Because I'm able to send data via input text field. – arikan May 14 '15 at 19:20
  • See my *very first comment*. The `mysql_* functions have been deprecated from your server. You're going to have to change your database API. – Jay Blanchard May 14 '15 at 19:34

0 Answers0