how to insert data into databse when a button is clicked

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
chitrapu
Forum Newbie
Posts: 23
Joined: Sun Jan 14, 2007 11:39 pm

how to insert data into databse when a button is clicked

Post by chitrapu »

arborint | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hiii everybody,

i have a little code that inserts the data into the databse. but the problem is the insertion should be peroformed only when a button is clicked. i  have problems in this because i am not able to call the function when the button is clicked. hope anyone can help me out with a good code.

Code: Select all

echo"Enter the name :"; 
echo"<input name='names' type='text'>";
echo"<input type='submit' value='ADD name' align=center><br>";
$link = mysql_connect("","","");
mysql_select_db("db");

/*the below statements must get executed only when the button is clicked*/



$query="insert into table value("");
mysql_query($query);

arborint | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

You could use a form that posts to a page with your insert code, and redirect back to the original.
Mohamed
Forum Newbie
Posts: 21
Joined: Fri Jan 19, 2007 6:59 pm
Location: Seattle

Post by Mohamed »

you can also use AJAX.
Post Reply