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.
php html mysql sql
add a comment |
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.
php html mysql sql
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
add a comment |
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.
php html mysql sql
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
php html mysql sql
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
add a comment |
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
add a comment |
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>
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
add a comment |
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">
add a comment |
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>
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
add a comment |
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>
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
add a comment |
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>
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>
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
add a comment |
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
add a comment |
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">
add a comment |
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">
add a comment |
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">
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">
edited Nov 11 at 10:08
marc_s
567k12810961247
567k12810961247
answered Aug 24 '15 at 12:31
mfisher91
524317
524317
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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