I need to update the SQL table every minute, as if typing on an online notepad, that save frequently. So of course, I have:

<textarea rows="20" cols="80" id="notepad">
<?php
	$con=mysql_connect("localhost","username","password");
	if(!$con)
	{
		die('Could not connect: '.mysql_error());
	}
	mysql_select_db("database", $con);
	$result = mysql_query("SELECT * FROM Notepad");
	while($row = mysql_fetch_array($result))
  	{
  		echo $row['Body'];
  	}
	mysql_close($con);
?>
</textarea>

(Passwords, usernames, and database names were changed.)
I have tried various things, including trying to put PHP in a Javascript SetTimeout using Function, but to no success. I am using the following to update, but it's missing a few things.

$con=mysql_connect("localhost","username","password");
if(!$con)
{
	die('Could not connect: '.mysql_error());
}
mysql_select_db("database", $con);
mysql_query("UPDATE Notepad SET Body='$missing_here'");
mysql_close($con);

My problem is that I don't know when to call it or how to get the text inside the textarea tags, any help?

I just want to update the database frequently, but I will add functionality later so that it updates the text inside the textarea as well. I am planning to use this so my and my team can edit a text at the same time, or is doing this the way I want to a bag thing?

You cannot put PHP in a Javascript function directly, but by using AJAX, you can call a PHP function (like a form post). There are several examples in this websites, so I suggest you search first.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.