Note that there are some explanatory texts on larger screens.

plurals
  1. POedit and update using jquery ajax
    primarykey
    data
    text
    <p>I've developed code to allow the user to edit and update details on the same page with AJAX methods. The update function is working perfectly. </p> <p>Below I have some images. In the first image, I'm fetching user details from the database. I would like an "edit profile" button to replace the text above with corresponding input fields to allow edits. How can I achieve this? Through JQuery, AJAX or div?</p> <p><strong>Before clicking edit button</strong></p> <p><img src="https://i.stack.imgur.com/r8e3R.png" alt="enter image description here"></p> <p><strong>After clicking edit button</strong></p> <p><img src="https://i.stack.imgur.com/7Gm9Y.png" alt="enter image description here"></p> <p><strong>PHP</strong></p> <pre><code>include('config.php'); $query = mysql_query("SELECT * FROM ebusers WHERE UserID = '26'"); while($row = mysql_fetch_array($query)) { echo "&lt;form id=updateform method=post action=update.php?id=" .$row['UserID']. "&gt;"; echo "&lt;input type=text name=uname value=" .$row['UserName']. "&gt;&lt;br&gt;"; echo "&lt;input type=text name=uemail value=" .$row['UserEmail']. "&gt;&lt;br&gt;"; echo "&lt;button id=upd&gt;Update&lt;/button&gt;&lt;br&gt;"; echo "&lt;/form&gt;"; echo "&lt;hr&gt;"; echo "&lt;span id=updateresult&gt;&lt;/span&gt;"; } </code></pre> <p><strong>AJAX</strong></p> <pre><code>$("#upd").click( function() { $.post( $("#updateform").attr("action"), $("#updateform :input").serializeArray(), function(info){ $("#updateresult").html(info); }); clearInput(); }); $("#updateform").submit( function() { return false; }); function clearInput() { $("#updateform :input").each( function() { $(this).val(''); }); } </code></pre> <p><strong>UPDATE.PHP</strong></p> <pre><code>include_once('config.php'); $getid = (int)$_GET['id']; $name = $_POST['uname']; $email = $_POST['uemail']; if(mysql_query("UPDATE ebusers SET UserName = '$name', UserEmail = '$email' WHERE UserID = '$getid'")) echo "Successfully updated"; else echo "Failed to update records"; </code></pre>
    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.
 

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