Updating database based on certain ID









up vote
0
down vote

favorite












I have a table within my database containing subscriptions, each subscription has a name, id and a notes column.



I'm trying to allow the user to update the notes column through a text area on the webpage. All of the subscriptions are in a list on the page which allows the user to click on them to view that specific subscription.



How would I make sure the note that is updated is correct with the id of the subscription they have clicked on?



I currently have this code.



<form method="POST" action="noteAction.php">
<textarea id="notes" name="noteValue">$notes</texarea>
<input type="submit" name="submit"/>
</form>


This is what I think my noteAction.php should look like however I cannot get it working.



 mysql_connect ("host", "user", "password") or die ('Error: ' . mysql_error());

mysql_select_db("database_name") or die ('Data error:' . mysql_error());

$text = mysql_real_escape_string($_POST['noteValue']);
$query="UPDATE `subscription` SET `notes`= '$text' WHERE `id` = '$id'";

mysql_query($query) or die ('Error updating database ' . mysql_error());


Any help would be great, thanks.










share|improve this question

















  • 1




    Where are you getting $id from?
    – Epodax
    Aug 24 '15 at 12:25










  • I'm not, I just think that's how the query should look? However I am unsure on how to query the id to make it work.
    – Andy
    Aug 24 '15 at 12:27










  • Send the ID with the form, I'm guessing you are getting the $notes data from somewhere, send the ID along there. I'd recommend you find a tutorial / guide on forms and mysql / php, it's fairly simple.
    – Epodax
    Aug 24 '15 at 12:28














up vote
0
down vote

favorite












I have a table within my database containing subscriptions, each subscription has a name, id and a notes column.



I'm trying to allow the user to update the notes column through a text area on the webpage. All of the subscriptions are in a list on the page which allows the user to click on them to view that specific subscription.



How would I make sure the note that is updated is correct with the id of the subscription they have clicked on?



I currently have this code.



<form method="POST" action="noteAction.php">
<textarea id="notes" name="noteValue">$notes</texarea>
<input type="submit" name="submit"/>
</form>


This is what I think my noteAction.php should look like however I cannot get it working.



 mysql_connect ("host", "user", "password") or die ('Error: ' . mysql_error());

mysql_select_db("database_name") or die ('Data error:' . mysql_error());

$text = mysql_real_escape_string($_POST['noteValue']);
$query="UPDATE `subscription` SET `notes`= '$text' WHERE `id` = '$id'";

mysql_query($query) or die ('Error updating database ' . mysql_error());


Any help would be great, thanks.










share|improve this question

















  • 1




    Where are you getting $id from?
    – Epodax
    Aug 24 '15 at 12:25










  • I'm not, I just think that's how the query should look? However I am unsure on how to query the id to make it work.
    – Andy
    Aug 24 '15 at 12:27










  • Send the ID with the form, I'm guessing you are getting the $notes data from somewhere, send the ID along there. I'd recommend you find a tutorial / guide on forms and mysql / php, it's fairly simple.
    – Epodax
    Aug 24 '15 at 12:28












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a table within my database containing subscriptions, each subscription has a name, id and a notes column.



I'm trying to allow the user to update the notes column through a text area on the webpage. All of the subscriptions are in a list on the page which allows the user to click on them to view that specific subscription.



How would I make sure the note that is updated is correct with the id of the subscription they have clicked on?



I currently have this code.



<form method="POST" action="noteAction.php">
<textarea id="notes" name="noteValue">$notes</texarea>
<input type="submit" name="submit"/>
</form>


This is what I think my noteAction.php should look like however I cannot get it working.



 mysql_connect ("host", "user", "password") or die ('Error: ' . mysql_error());

mysql_select_db("database_name") or die ('Data error:' . mysql_error());

$text = mysql_real_escape_string($_POST['noteValue']);
$query="UPDATE `subscription` SET `notes`= '$text' WHERE `id` = '$id'";

mysql_query($query) or die ('Error updating database ' . mysql_error());


Any help would be great, thanks.










share|improve this question













I have a table within my database containing subscriptions, each subscription has a name, id and a notes column.



I'm trying to allow the user to update the notes column through a text area on the webpage. All of the subscriptions are in a list on the page which allows the user to click on them to view that specific subscription.



How would I make sure the note that is updated is correct with the id of the subscription they have clicked on?



I currently have this code.



<form method="POST" action="noteAction.php">
<textarea id="notes" name="noteValue">$notes</texarea>
<input type="submit" name="submit"/>
</form>


This is what I think my noteAction.php should look like however I cannot get it working.



 mysql_connect ("host", "user", "password") or die ('Error: ' . mysql_error());

mysql_select_db("database_name") or die ('Data error:' . mysql_error());

$text = mysql_real_escape_string($_POST['noteValue']);
$query="UPDATE `subscription` SET `notes`= '$text' WHERE `id` = '$id'";

mysql_query($query) or die ('Error updating database ' . mysql_error());


Any help would be great, thanks.







php html mysql sql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 24 '15 at 12:23









Andy

8910




8910







  • 1




    Where are you getting $id from?
    – Epodax
    Aug 24 '15 at 12:25










  • I'm not, I just think that's how the query should look? However I am unsure on how to query the id to make it work.
    – Andy
    Aug 24 '15 at 12:27










  • Send the ID with the form, I'm guessing you are getting the $notes data from somewhere, send the ID along there. I'd recommend you find a tutorial / guide on forms and mysql / php, it's fairly simple.
    – Epodax
    Aug 24 '15 at 12:28












  • 1




    Where are you getting $id from?
    – Epodax
    Aug 24 '15 at 12:25










  • I'm not, I just think that's how the query should look? However I am unsure on how to query the id to make it work.
    – Andy
    Aug 24 '15 at 12:27










  • Send the ID with the form, I'm guessing you are getting the $notes data from somewhere, send the ID along there. I'd recommend you find a tutorial / guide on forms and mysql / php, it's fairly simple.
    – Epodax
    Aug 24 '15 at 12:28







1




1




Where are you getting $id from?
– Epodax
Aug 24 '15 at 12:25




Where are you getting $id from?
– Epodax
Aug 24 '15 at 12:25












I'm not, I just think that's how the query should look? However I am unsure on how to query the id to make it work.
– Andy
Aug 24 '15 at 12:27




I'm not, I just think that's how the query should look? However I am unsure on how to query the id to make it work.
– Andy
Aug 24 '15 at 12:27












Send the ID with the form, I'm guessing you are getting the $notes data from somewhere, send the ID along there. I'd recommend you find a tutorial / guide on forms and mysql / php, it's fairly simple.
– Epodax
Aug 24 '15 at 12:28




Send the ID with the form, I'm guessing you are getting the $notes data from somewhere, send the ID along there. I'd recommend you find a tutorial / guide on forms and mysql / php, it's fairly simple.
– Epodax
Aug 24 '15 at 12:28












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










Use hidden element to store your id inside it.



 <form method="POST" action="noteAction.php">
<textarea id="notes" name="noteValue">$notes</texarea>
<input type="hidden" name="id" value="id" value="your id goes here" />
<input type="submit" name="submit"/>
</form>





share|improve this answer




















  • Thank you I never thought to use a hidden element to pass the id through, managed to fix the issue!
    – Andy
    Aug 24 '15 at 13:22

















up vote
1
down vote













When you're putting the note in the form, you must have an id for that note kicking about somewhere, after you retrieved it from the database. If you only selected the note contents in that query, select the ID as well. Then pass the ID over in a hidden field, and you have the ID to use in the MySQL query (which is correct).



<input type="hidden" name="note-id" value="note_id_here">





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32182237%2fupdating-database-based-on-certain-id%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    Use hidden element to store your id inside it.



     <form method="POST" action="noteAction.php">
    <textarea id="notes" name="noteValue">$notes</texarea>
    <input type="hidden" name="id" value="id" value="your id goes here" />
    <input type="submit" name="submit"/>
    </form>





    share|improve this answer




















    • Thank you I never thought to use a hidden element to pass the id through, managed to fix the issue!
      – Andy
      Aug 24 '15 at 13:22














    up vote
    1
    down vote



    accepted










    Use hidden element to store your id inside it.



     <form method="POST" action="noteAction.php">
    <textarea id="notes" name="noteValue">$notes</texarea>
    <input type="hidden" name="id" value="id" value="your id goes here" />
    <input type="submit" name="submit"/>
    </form>





    share|improve this answer




















    • Thank you I never thought to use a hidden element to pass the id through, managed to fix the issue!
      – Andy
      Aug 24 '15 at 13:22












    up vote
    1
    down vote



    accepted







    up vote
    1
    down vote



    accepted






    Use hidden element to store your id inside it.



     <form method="POST" action="noteAction.php">
    <textarea id="notes" name="noteValue">$notes</texarea>
    <input type="hidden" name="id" value="id" value="your id goes here" />
    <input type="submit" name="submit"/>
    </form>





    share|improve this answer












    Use hidden element to store your id inside it.



     <form method="POST" action="noteAction.php">
    <textarea id="notes" name="noteValue">$notes</texarea>
    <input type="hidden" name="id" value="id" value="your id goes here" />
    <input type="submit" name="submit"/>
    </form>






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 24 '15 at 12:34









    Shailesh Katarmal

    2,3371612




    2,3371612











    • Thank you I never thought to use a hidden element to pass the id through, managed to fix the issue!
      – Andy
      Aug 24 '15 at 13:22
















    • Thank you I never thought to use a hidden element to pass the id through, managed to fix the issue!
      – Andy
      Aug 24 '15 at 13:22















    Thank you I never thought to use a hidden element to pass the id through, managed to fix the issue!
    – Andy
    Aug 24 '15 at 13:22




    Thank you I never thought to use a hidden element to pass the id through, managed to fix the issue!
    – Andy
    Aug 24 '15 at 13:22












    up vote
    1
    down vote













    When you're putting the note in the form, you must have an id for that note kicking about somewhere, after you retrieved it from the database. If you only selected the note contents in that query, select the ID as well. Then pass the ID over in a hidden field, and you have the ID to use in the MySQL query (which is correct).



    <input type="hidden" name="note-id" value="note_id_here">





    share|improve this answer


























      up vote
      1
      down vote













      When you're putting the note in the form, you must have an id for that note kicking about somewhere, after you retrieved it from the database. If you only selected the note contents in that query, select the ID as well. Then pass the ID over in a hidden field, and you have the ID to use in the MySQL query (which is correct).



      <input type="hidden" name="note-id" value="note_id_here">





      share|improve this answer
























        up vote
        1
        down vote










        up vote
        1
        down vote









        When you're putting the note in the form, you must have an id for that note kicking about somewhere, after you retrieved it from the database. If you only selected the note contents in that query, select the ID as well. Then pass the ID over in a hidden field, and you have the ID to use in the MySQL query (which is correct).



        <input type="hidden" name="note-id" value="note_id_here">





        share|improve this answer














        When you're putting the note in the form, you must have an id for that note kicking about somewhere, after you retrieved it from the database. If you only selected the note contents in that query, select the ID as well. Then pass the ID over in a hidden field, and you have the ID to use in the MySQL query (which is correct).



        <input type="hidden" name="note-id" value="note_id_here">






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 11 at 10:08









        marc_s

        567k12810961247




        567k12810961247










        answered Aug 24 '15 at 12:31









        mfisher91

        524317




        524317



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32182237%2fupdating-database-based-on-certain-id%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3