[Solved] How would I create a button that links to records on my database? [closed]


Generally you should do it the following way:

  1. Attach an event to the button just as @Marc B suggested
  2. In the function for the event do a jQuery.ajax request, sending the users name (type to POST would be a good idea and the users name inside data)
  3. On the server create a PHP file (for example setname.php) that has the URL you used for the ajax request
  4. In the PHP file take the name from $_POST['name'] and file_put_contents it into any file (let’s say lastbuttonclicker.txt)
  5. Go back to the JS and make a window.setInterval(..., 1000); which runs another JS function
  6. In that function from step 5, do another ajax request (via jQuery.ajax and add it via jQuery.fn.text, not jQuery.fn.html and don’t use jQuery.fn.load!!! That way users could write HTML into other users interfaces doing very bad things) to another PHP file (for example getname.php)
  7. In that PHP file just do <?php echo file_get_contents('lastbuttonclicker.txt'); ?>

But after all be aware, that users can put offensive names there. But that is a topic for itself.

EDIT: You should also ensure, that the content has a suitable length, at the server side (checking inside JavaScript has no impact to bad people writing gigabytes of text to everybodys client and your server).

EDIT 2: <facepalm> Of course you dont need step 7, just load the lastbuttonclicker.txt itself in step 6 instead of getname.php

solved How would I create a button that links to records on my database? [closed]