I am new to PHP I have a running website and I have no problems getting data or adding data to my database.
I am trying to update information in the database when someone clicks a button and then refrsh that data to an HTML textarea. I can do this now but it refreshes the whole page.
Right now I just have a form that calls the page and that refreshes everything even the page.
Can someone help me figure out how to update the data without updating the whole page?
Thank you -newbie
Refrshing data but not the whole page~
Moderator: General Moderators
I have a php function that I need to call when a button is pressed. I am basically trying to update the database without reloading the page. When this page is first accessed it seems to call the updatedata function. I only want to do this when the button ispressed. Any ideas how I can make this work? I searched the forums with no luck.
Thank you -WM
<?php
function updatedata(){
$db=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database1_chatdb");
$sql = "INSERT INTO messages VALUES ('testnick', sysdate(),'msgtxt','')";
$sql_query = mysql_query($sql,$db);
}
?>
<?php
$nick=$_POST['nick'];
if($nick==""){$nick=$_GET['nick'];}
printf("%s","<form name='message_submit_text' method='POST' action='info.php?req=chat&nick=$nick'>");
?>
<input type=text name="messagetext">
<input type=hidden value="messagesubmit" name="posttype">
<input type=submit value="Chat" name="submit">
</form>
<input type="button" value="Chat2" name="addMsg" action="<?php updatedata(); ?>">
Thank you -WM
<?php
function updatedata(){
$db=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database1_chatdb");
$sql = "INSERT INTO messages VALUES ('testnick', sysdate(),'msgtxt','')";
$sql_query = mysql_query($sql,$db);
}
?>
<?php
$nick=$_POST['nick'];
if($nick==""){$nick=$_GET['nick'];}
printf("%s","<form name='message_submit_text' method='POST' action='info.php?req=chat&nick=$nick'>");
?>
<input type=text name="messagetext">
<input type=hidden value="messagesubmit" name="posttype">
<input type=submit value="Chat" name="submit">
</form>
<input type="button" value="Chat2" name="addMsg" action="<?php updatedata(); ?>">
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK