Answer the question
In order to leave comments, you need to log in
How to execute SQL query on button click?
Hello, I'm new to web development and I need a SQL query to be executed when a button is clicked. Is it possible to do this through Ajax, and is it safe at all (I read somewhere that data can be stolen from the database in this way). Or maybe there is an easier way? If it needs to be done via Ajax anyway, can you explain to me how to do it please.
Here is the button code and the SQL query itself:
<?php
echo '<input type="Submit" name="sendMessage" value="Написати продавцю" onclick="window.location.href=\'send_message.php?itemid='.$row['idItem'] .'\'; return false;" >';
if (isset($_POST['sendMessage']))
{
$_SESSION['sellerEmail'] = $row['itemSellerEmail'];
}
?>
Answer the question
In order to leave comments, you need to log in
Is it possible to do this through Ajax, and is it safe at all (I read somewhere that data can be stolen from the database in this way).
I wrote to you yesterday, I will write to you today.
There is no SQL query in the above code.
To submit form data to the handler file, you need to
1) Wrap your input in a form tag.
2) Specify the necessary attributes for the form tag: action="the file you need.php" action="POST". For other attributes of the form tag, information should be taken from the official HTML documentation from w3c.
3) Add a button with the Submit type to the form.
Also learn the difference between POST and GET.
Don't touch AJAX yet - you still need to grow up to it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question