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.

5
  • Are you getting an error? If so please edit your result to include it Commented Apr 24, 2015 at 2: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. Commented Apr 24, 2015 at 2:33
  • Don't just put user input into your SQL queries, that's how you get injected. stackoverflow.com/questions/60174/… Commented Apr 24, 2015 at 2:52
  • Please only use tags relevant to your problem. This issue has nothing to do with javascript or jQuery Commented Apr 24, 2015 at 2:58
  • update query is incorrect. First correct it and then try. Or Check your rid = '$id' variable is it correct id or not. Commented Apr 24, 2015 at 7:28

2 Answers 2

2

Your update SQL is incorrect. Try this:

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

Hope that helps!

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.