Deleting a row in mysql that I have entered through queries using a delete message button
So I am creating a wall where people can send messages to other users. In my SQL I have two tables one for users and one for messages and the tables are labeled as such.
In my table for messages the column names are id, sender_id, message, created_at, updated_at, and recipient_id. The users table columns are as follows id, firstName, lastName, email, password(hashed), created_at, updated_at.
Sending messages is fine. But when i tried creating a route to delete message in that person's wall i cant seem to get it to work.
the following is my code from my server.py file:
@app.route("/delete/<id>", methods=["POST"])
def delete(id):
mysql=connectToMySQL('logindb')
query = "DELETE FROM messages WHERE (id = request.form['user_id']) and (sender_id = session['sender_id]);"
# DELETE FROM `logindb`.`messages` WHERE (`id` = '51') and (`sender_id` = '12');
selecter = mysql.query_db(query)
return redirect('/wall')
(the commented out code is my it looked in mySQL)
following is my create message route:
@app.route('/create_messages', methods=['POST'])
def create_messages():
mysql=connectToMySQL('logindb')
query = "INSERT INTO messages(message, created_at, updated_at, sender_id, recipient_id) values(%(messages)s, now(), now(), %(sender_id)s, %(recipient_id)s)"
data =
'messages' : request.form['message'],
'sender_id' : session['id'],
'recipient_id' : request.form['user_id']
session['recipient_id'] = request.form['user_id']
session['sender_id'] = session['id']
print(session['recipient_id'],'THIS IS THE RECIPIENT ID !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
print(session['sender_id'],'THIS IS THE SENDER ID !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
inserter = mysql.query_db(query,data)
return redirect('/wall')
On my wall.html file. I have two sections. The section on the right is to create messages and the left is the messages that that specific user has. I also have an error here that I want to fix if you can help me with, but this is a minor error. So in the section where you can send messages somehow the logged in user can send messages to himself... I didnt intend to do that, but i thought it might be cool kind of like reminders, but I do want to see if i can fix that as well.
Create message side:
<div class="right_messages">
%for messages in create%
<form action="/create_messages" method="post">
messages['firstName']
<textarea name="message"></textarea>
<input type="hidden" name="user_id" value=messages['id']>
<input type="submit" value="send">
</form>
%endfor%
</div>
See and delete message side:
<div class="left_messages">
<h3>count message(s) for you session['firstName']!</h3>
<div class="messages">
%for messages in message%
<p>messages['firstName'] said at messages['created_at'] <br> messages['message']</p>
<form method="post" action="/delete/message.id">
<input type="hidden" value="message.id" name="id">
<input type="submit" value="delete">
</form>
%endfor%
</div>
</div>
I tried using hidden inputs to do my transferring of the message id, but i couldn't implement it..
Any help would be greatly appreciated.
python html mysql flask jinja2
add a comment |
So I am creating a wall where people can send messages to other users. In my SQL I have two tables one for users and one for messages and the tables are labeled as such.
In my table for messages the column names are id, sender_id, message, created_at, updated_at, and recipient_id. The users table columns are as follows id, firstName, lastName, email, password(hashed), created_at, updated_at.
Sending messages is fine. But when i tried creating a route to delete message in that person's wall i cant seem to get it to work.
the following is my code from my server.py file:
@app.route("/delete/<id>", methods=["POST"])
def delete(id):
mysql=connectToMySQL('logindb')
query = "DELETE FROM messages WHERE (id = request.form['user_id']) and (sender_id = session['sender_id]);"
# DELETE FROM `logindb`.`messages` WHERE (`id` = '51') and (`sender_id` = '12');
selecter = mysql.query_db(query)
return redirect('/wall')
(the commented out code is my it looked in mySQL)
following is my create message route:
@app.route('/create_messages', methods=['POST'])
def create_messages():
mysql=connectToMySQL('logindb')
query = "INSERT INTO messages(message, created_at, updated_at, sender_id, recipient_id) values(%(messages)s, now(), now(), %(sender_id)s, %(recipient_id)s)"
data =
'messages' : request.form['message'],
'sender_id' : session['id'],
'recipient_id' : request.form['user_id']
session['recipient_id'] = request.form['user_id']
session['sender_id'] = session['id']
print(session['recipient_id'],'THIS IS THE RECIPIENT ID !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
print(session['sender_id'],'THIS IS THE SENDER ID !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
inserter = mysql.query_db(query,data)
return redirect('/wall')
On my wall.html file. I have two sections. The section on the right is to create messages and the left is the messages that that specific user has. I also have an error here that I want to fix if you can help me with, but this is a minor error. So in the section where you can send messages somehow the logged in user can send messages to himself... I didnt intend to do that, but i thought it might be cool kind of like reminders, but I do want to see if i can fix that as well.
Create message side:
<div class="right_messages">
%for messages in create%
<form action="/create_messages" method="post">
messages['firstName']
<textarea name="message"></textarea>
<input type="hidden" name="user_id" value=messages['id']>
<input type="submit" value="send">
</form>
%endfor%
</div>
See and delete message side:
<div class="left_messages">
<h3>count message(s) for you session['firstName']!</h3>
<div class="messages">
%for messages in message%
<p>messages['firstName'] said at messages['created_at'] <br> messages['message']</p>
<form method="post" action="/delete/message.id">
<input type="hidden" value="message.id" name="id">
<input type="submit" value="delete">
</form>
%endfor%
</div>
</div>
I tried using hidden inputs to do my transferring of the message id, but i couldn't implement it..
Any help would be greatly appreciated.
python html mysql flask jinja2
not a python/flask expert. Still looks like, the parameter passed-in is not the one used in the controller action. POST url parameter you send through<form method="post" action="/delete/message.id">to@app.route("/delete/<id>", methods=["POST"])should hold the message.id in the 'id' variable. Should that not be used in the query instead of comparing torequest.form['user_id']?
– Raj
Nov 15 '18 at 22:47
thanks Raj, i figured out my problem. My id was not getting through. I forgot the actually problem, but ya thanks for your help.
– jonathan jen
Nov 21 '18 at 21:45
add a comment |
So I am creating a wall where people can send messages to other users. In my SQL I have two tables one for users and one for messages and the tables are labeled as such.
In my table for messages the column names are id, sender_id, message, created_at, updated_at, and recipient_id. The users table columns are as follows id, firstName, lastName, email, password(hashed), created_at, updated_at.
Sending messages is fine. But when i tried creating a route to delete message in that person's wall i cant seem to get it to work.
the following is my code from my server.py file:
@app.route("/delete/<id>", methods=["POST"])
def delete(id):
mysql=connectToMySQL('logindb')
query = "DELETE FROM messages WHERE (id = request.form['user_id']) and (sender_id = session['sender_id]);"
# DELETE FROM `logindb`.`messages` WHERE (`id` = '51') and (`sender_id` = '12');
selecter = mysql.query_db(query)
return redirect('/wall')
(the commented out code is my it looked in mySQL)
following is my create message route:
@app.route('/create_messages', methods=['POST'])
def create_messages():
mysql=connectToMySQL('logindb')
query = "INSERT INTO messages(message, created_at, updated_at, sender_id, recipient_id) values(%(messages)s, now(), now(), %(sender_id)s, %(recipient_id)s)"
data =
'messages' : request.form['message'],
'sender_id' : session['id'],
'recipient_id' : request.form['user_id']
session['recipient_id'] = request.form['user_id']
session['sender_id'] = session['id']
print(session['recipient_id'],'THIS IS THE RECIPIENT ID !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
print(session['sender_id'],'THIS IS THE SENDER ID !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
inserter = mysql.query_db(query,data)
return redirect('/wall')
On my wall.html file. I have two sections. The section on the right is to create messages and the left is the messages that that specific user has. I also have an error here that I want to fix if you can help me with, but this is a minor error. So in the section where you can send messages somehow the logged in user can send messages to himself... I didnt intend to do that, but i thought it might be cool kind of like reminders, but I do want to see if i can fix that as well.
Create message side:
<div class="right_messages">
%for messages in create%
<form action="/create_messages" method="post">
messages['firstName']
<textarea name="message"></textarea>
<input type="hidden" name="user_id" value=messages['id']>
<input type="submit" value="send">
</form>
%endfor%
</div>
See and delete message side:
<div class="left_messages">
<h3>count message(s) for you session['firstName']!</h3>
<div class="messages">
%for messages in message%
<p>messages['firstName'] said at messages['created_at'] <br> messages['message']</p>
<form method="post" action="/delete/message.id">
<input type="hidden" value="message.id" name="id">
<input type="submit" value="delete">
</form>
%endfor%
</div>
</div>
I tried using hidden inputs to do my transferring of the message id, but i couldn't implement it..
Any help would be greatly appreciated.
python html mysql flask jinja2
So I am creating a wall where people can send messages to other users. In my SQL I have two tables one for users and one for messages and the tables are labeled as such.
In my table for messages the column names are id, sender_id, message, created_at, updated_at, and recipient_id. The users table columns are as follows id, firstName, lastName, email, password(hashed), created_at, updated_at.
Sending messages is fine. But when i tried creating a route to delete message in that person's wall i cant seem to get it to work.
the following is my code from my server.py file:
@app.route("/delete/<id>", methods=["POST"])
def delete(id):
mysql=connectToMySQL('logindb')
query = "DELETE FROM messages WHERE (id = request.form['user_id']) and (sender_id = session['sender_id]);"
# DELETE FROM `logindb`.`messages` WHERE (`id` = '51') and (`sender_id` = '12');
selecter = mysql.query_db(query)
return redirect('/wall')
(the commented out code is my it looked in mySQL)
following is my create message route:
@app.route('/create_messages', methods=['POST'])
def create_messages():
mysql=connectToMySQL('logindb')
query = "INSERT INTO messages(message, created_at, updated_at, sender_id, recipient_id) values(%(messages)s, now(), now(), %(sender_id)s, %(recipient_id)s)"
data =
'messages' : request.form['message'],
'sender_id' : session['id'],
'recipient_id' : request.form['user_id']
session['recipient_id'] = request.form['user_id']
session['sender_id'] = session['id']
print(session['recipient_id'],'THIS IS THE RECIPIENT ID !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
print(session['sender_id'],'THIS IS THE SENDER ID !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
inserter = mysql.query_db(query,data)
return redirect('/wall')
On my wall.html file. I have two sections. The section on the right is to create messages and the left is the messages that that specific user has. I also have an error here that I want to fix if you can help me with, but this is a minor error. So in the section where you can send messages somehow the logged in user can send messages to himself... I didnt intend to do that, but i thought it might be cool kind of like reminders, but I do want to see if i can fix that as well.
Create message side:
<div class="right_messages">
%for messages in create%
<form action="/create_messages" method="post">
messages['firstName']
<textarea name="message"></textarea>
<input type="hidden" name="user_id" value=messages['id']>
<input type="submit" value="send">
</form>
%endfor%
</div>
See and delete message side:
<div class="left_messages">
<h3>count message(s) for you session['firstName']!</h3>
<div class="messages">
%for messages in message%
<p>messages['firstName'] said at messages['created_at'] <br> messages['message']</p>
<form method="post" action="/delete/message.id">
<input type="hidden" value="message.id" name="id">
<input type="submit" value="delete">
</form>
%endfor%
</div>
</div>
I tried using hidden inputs to do my transferring of the message id, but i couldn't implement it..
Any help would be greatly appreciated.
python html mysql flask jinja2
python html mysql flask jinja2
edited Nov 15 '18 at 22:22
jonathan jen
asked Nov 15 '18 at 22:05
jonathan jenjonathan jen
92
92
not a python/flask expert. Still looks like, the parameter passed-in is not the one used in the controller action. POST url parameter you send through<form method="post" action="/delete/message.id">to@app.route("/delete/<id>", methods=["POST"])should hold the message.id in the 'id' variable. Should that not be used in the query instead of comparing torequest.form['user_id']?
– Raj
Nov 15 '18 at 22:47
thanks Raj, i figured out my problem. My id was not getting through. I forgot the actually problem, but ya thanks for your help.
– jonathan jen
Nov 21 '18 at 21:45
add a comment |
not a python/flask expert. Still looks like, the parameter passed-in is not the one used in the controller action. POST url parameter you send through<form method="post" action="/delete/message.id">to@app.route("/delete/<id>", methods=["POST"])should hold the message.id in the 'id' variable. Should that not be used in the query instead of comparing torequest.form['user_id']?
– Raj
Nov 15 '18 at 22:47
thanks Raj, i figured out my problem. My id was not getting through. I forgot the actually problem, but ya thanks for your help.
– jonathan jen
Nov 21 '18 at 21:45
not a python/flask expert. Still looks like, the parameter passed-in is not the one used in the controller action. POST url parameter you send through
<form method="post" action="/delete/message.id"> to @app.route("/delete/<id>", methods=["POST"]) should hold the message.id in the 'id' variable. Should that not be used in the query instead of comparing to request.form['user_id'] ?– Raj
Nov 15 '18 at 22:47
not a python/flask expert. Still looks like, the parameter passed-in is not the one used in the controller action. POST url parameter you send through
<form method="post" action="/delete/message.id"> to @app.route("/delete/<id>", methods=["POST"]) should hold the message.id in the 'id' variable. Should that not be used in the query instead of comparing to request.form['user_id'] ?– Raj
Nov 15 '18 at 22:47
thanks Raj, i figured out my problem. My id was not getting through. I forgot the actually problem, but ya thanks for your help.
– jonathan jen
Nov 21 '18 at 21:45
thanks Raj, i figured out my problem. My id was not getting through. I forgot the actually problem, but ya thanks for your help.
– jonathan jen
Nov 21 '18 at 21:45
add a comment |
0
active
oldest
votes
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',
autoActivateHeartbeat: false,
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
);
);
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%2f53328541%2fdeleting-a-row-in-mysql-that-i-have-entered-through-queries-using-a-delete-messa%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
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%2f53328541%2fdeleting-a-row-in-mysql-that-i-have-entered-through-queries-using-a-delete-messa%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
not a python/flask expert. Still looks like, the parameter passed-in is not the one used in the controller action. POST url parameter you send through
<form method="post" action="/delete/message.id">to@app.route("/delete/<id>", methods=["POST"])should hold the message.id in the 'id' variable. Should that not be used in the query instead of comparing torequest.form['user_id']?– Raj
Nov 15 '18 at 22:47
thanks Raj, i figured out my problem. My id was not getting through. I forgot the actually problem, but ya thanks for your help.
– jonathan jen
Nov 21 '18 at 21:45