Refrshing data but not the whole page~

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Deus
Forum Newbie
Posts: 5
Joined: Mon Dec 08, 2003 8:43 pm

Refrshing data but not the whole page~

Post 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
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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?
Deus
Forum Newbie
Posts: 5
Joined: Mon Dec 08, 2003 8:43 pm

Post 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?
Deus
Forum Newbie
Posts: 5
Joined: Mon Dec 08, 2003 8:43 pm

Post 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(); ?>">
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Have you tried using some Javascript?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have a read of:
viewtopic.php?t=1030

Mac
Post Reply