1

I'm already displaying the MySQL data in a PHP table with a edit function, but I'm not able to edit them, and I don't know why.

<?php
require("db.php");
$id =$_REQUEST['rid'];

$result = mysql_query("SELECT * FROM replies WHERE rid = '$id'");
$test = mysql_fetch_array($result);
if (!$result) 
        {
        die("Error: Data not found..");
        }
                $trigger1=$test['trigger1'] ;
                $reply2= $test['reply2'] ;              

if (isset($_POST['save']))
{   
    $triggera = $_POST['trigger1'];
    $replyb = $_POST['reply2'];

    mysql_query("UPDATE `replies`(trigger,reply) VALUES ('$triggera','$replyb') WHERE rid = '$id'");  
    echo "Saved!";

}
mysql_close($conn);
?>

And this is MySQL database code:

CREATE TABLE IF NOT EXISTS `replies` (
  `trigger` text NOT NULL,
  `reply` text NOT NULL,
  `usercontrib` tinyint(4) NOT NULL DEFAULT '0',
  `rid` int(10) unsigned NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=332 DEFAULT CHARSET=utf8;

and finally:

    <form method="post">
        <table>
            <tr>
                <td>Title:</td>
                <td><input type="text" name="trigger" value="<?php echo $trigger1 ?>"/></td>
            </tr>
            <tr>
                <td>Author</td>
                <td><input type="text" name="reply" value="<?php echo $reply2 ?>"/></td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td><input type="submit" name="save" value="save" /></td>
            </tr>
        </table>
    </form>

When I click "edit" in the specifically data to modify, the fields in the "edit" page are empty, I think the "echo" on thme is not function.

ssube
  • 47,010
  • 7
  • 103
  • 140
  • Are you getting an error? If so please edit your result to include it – nomistic Apr 24 '15 at 02:31
  • No, the result of edtion is just not apering and not modifying the database... Ths input field should be displaying the specifficly original data os mysql database there is gonna to be modifyed. –  Apr 24 '15 at 02:33
  • Don't just put user input into your SQL queries, that's how you get injected. http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1 – chris85 Apr 24 '15 at 02:52
  • Please only use tags relevant to your problem. This issue has nothing to do with javascript or jQuery – charlietfl Apr 24 '15 at 02:58
  • update query is incorrect. First correct it and then try. Or Check your rid = '$id' variable is it correct id or not. – Lakhan Apr 24 '15 at 07:28

2 Answers2

2

Your update SQL is incorrect. Try this:

UPDATE `replies` SET trigger = '$triggera', reply = '$replyb' WHERE rid = '$rid'

Hope that helps!

Chip Dean
  • 4,222
  • 3
  • 24
  • 36
0

$_POST array will have key exactly same from the value of 'name' attribute in HTML form. So where you are checking if save isset in your php program you need to make following change -

$triggera = $_POST['trigger'];
$replyb = $_POST['reply'];

Also to check you can try printing the POST array on the page using print_r method.