Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks guys, initial problem was as you suggested with me forgetting to wait for the dom to load before executing the script. Second problem was some small bracket and syntax errors in the script.</p> <p>Final code is below</p> <p>HTML / Jquery</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; $(function () { $("#weight_tracker_form").submit(function() { $.ajax({ type: "POST", url: "weight_tracker_process.php", data: { weight: $("#weight").val() }, 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; &lt;a href="logout.php"&gt;Log Out&lt;/a&gt; </code></pre> <p>PHP</p> <pre><code>&lt;?php // configuration require("includes/config.php"); // if form was submitted if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_POST["weight"] == NULL) { echo "Error"; } $weight = mysql_real_escape_string($_POST["weight"]); if (query("INSERT INTO weight (user_id, weight_measurement) VALUES(?, ?)", $_SESSION["id"], $weight) == false){ echo "Update Error"; } else { echo "Success"; } } else { // else render form printf("error"); } ?&gt; </code></pre>
 

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