Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function SubmitForm() {
- var input = $("#input").val();
- var user = "anon";
- $.post("post.php", {input: input, user: user}, function(data) {});
- alert("hello");
- }
- function SubmitForm() {
- var input = $("#input").val();
- var user = "anon";
- $.post("post.php", {input: input, user: user}, function(data) {});
- }
- <?php
- $dbhost = "xxx";
- $dbname = "xxx";
- $dbuser = "xxx";
- $dbpass = "xxx";
- // Create connection
- $con = mysqli_connect($dbhost, $dbuser, $dbpass);
- // Check connection
- if (!$con) {
- die("Database connection failed: " . mysqli_error());
- }
- // Select database
- $db_select = mysqli_select_db($con, $dbname);
- // Check selection
- if (!$db_select) {
- die("Database selection failed: " . mysqli_error());
- }
- $message = $_POST["input"];
- $user = $_POST["user"];
- echo $message;
- echo $user;
- $query = "INSERT INTO posts (user, message) VALUES ('$user', '$message')";
- mysqli_query($con, $query);
- ?>
- <input type="submit" class="button" id="button_post" value="POST" onclick="SubmitForm(); return false;">
- <input type="submit" class="button" id="button_post" value="POST">
- <script>
- $(function(){
- $('#button_post').click(function(e){
- e.preventDefault();
- SubmitForm();
- });
- });
- </script>
- function SubmitForm() {
- var input = $("#input").val();
- var user = "anon";
- $.post("post.php", {input: input, user: user}, function(data) {
- alert(data);
- });
- }
- $.post("post.php", {input: input, user: user}, function(data) {
- // do anything that relies on this post here
- });
- <input type="submit" class="button" id="button_post" value="POST" onclick="SubmitForm();">
- <input type="button" ...
- <input ... onclick="SubmitForm(); return false;">
- $(window).load(function(){
- // your function here.
- });
Add Comment
Please, Sign In to add comment