Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to update a database via AJAX and Jquery
    primarykey
    data
    text
    <p>I'm trying to achieve something basic, where you submit a form with a weight and it updates my database via ajax.</p> <p>I've been looking through some of the answered questions for guidance but I just can't figure out why the below code doesn't work.</p> <p>looking in chrome developer tools it look like it's not even submitting the form properly, so I don't think its the php script that's the issue (although it may have other issues once I fix the first problem).</p> <p>Any help with fixing this would be much appreciated.</p> <p>Here's the form and Ajax code</p> <pre><code>&lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $("#weight_tracker_form").submit(function() { $.ajax({ type: "POST", url: "../weight_tracker_process.php", data: { weight: $("#weight").attr("value"), }, success: function(){ alert("success"); }, error: function(){ alert("error"); } }); return false; }); &lt;/script&gt; &lt;h2&gt;Weight Tracker&lt;/h2&gt; &lt;form id="weight_tracker_form" method="post"&gt; Date: &lt;input autofocus id="date" name="date" type="date"/&gt; Weight: &lt;input id="weight" name="weight" type="text"/&gt; Kg &lt;input type="submit" value="Submit Weight"&gt; &lt;/form&gt; </code></pre> <p>And here's the script weight_tracker_process.php</p> <pre><code>&lt;?php // configuration require("includes/config.php"); if ($_POST["weight"] == NULL) { apologize("Please enter an email"); } $weight = mysql_real_escape_string($_POST["weight"]); $date = mysql_real_escape_string($_POST["date"]); if (query("INSERT INTO weight (user_id, weight_measurement) VALUES (?, ?)", $_SESSION["id"], $weight); == false){ echo "Update Error"; } else { echo "Success"; } ?&gt; </code></pre> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload