Page 1 of 1

Refrshing data but not the whole page~

Posted: Mon Dec 08, 2003 8:43 pm
by Deus
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

Posted: Mon Dec 08, 2003 8:48 pm
by qads
well, you could place the update code before the query which gets the data out, that way it will update the data first AND THEN get it out...make sense?

Posted: Mon Dec 08, 2003 9:04 pm
by Deus
I have that now. the problem I am having is updating the database and text area without refreshing the whole page. Any ideas?

Posted: Tue Dec 09, 2003 3:29 am
by Deus
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(); ?>">

Posted: Tue Dec 09, 2003 3:56 am
by Pyrite
Have you tried using some Javascript?

Posted: Tue Dec 09, 2003 4:27 am
by twigletmac
Have a read of:
viewtopic.php?t=1030

Mac