Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Update a MySQL table via a form button?

Posted on 2011-03-16
3
Medium Priority
?
371 Views
Last Modified: 2012-08-13
Hi,
If I have a table as below, how would I update the table using PHP/MySQl/Javascript via an "add to friends" button?
Say if one id was "17" and the other was "46"

Thanks in advance for your feedback.


CREATE TABLE IF NOT EXISTS `friends` (
  `id` int(11) NOT NULL auto_increment,
  `toid` int(11) NOT NULL,
  `fromid` int(11) NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

--
-- Dumping data for table `friends`
--

INSERT INTO `friends` (`id`, `toid`, `fromid`) VALUES
(1, 17, 2007),
(2, 2007, 17),
(3, 17, 11),
(4, 11, 17),
(5, 17, 26),
(6, 26, 17);
0
Comment
Question by:sabecs
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 1500 total points
ID: 35154073
refer this to insert data in table


<?php
// Make a MySQL Connection
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

// Insert a row of information into the table "example"
mysql_query("INSERT INTO example
(name, age) VALUES('Timmy Mellowman', '23' ) ")
or die(mysql_error());  

mysql_query("INSERT INTO example
(name, age) VALUES('Sandy Smith', '21' ) ")
or die(mysql_error());  

mysql_query("INSERT INTO example
(name, age) VALUES('Bobby Wallace', '15' ) ")
or die(mysql_error());  

echo "Data Inserted!";

?>
0
 

Author Comment

by:sabecs
ID: 35177091
thanks for you feed back, I know how to insert the data, I need the code to execute the javascript required update my table via PHP.
0
 

Author Closing Comment

by:sabecs
ID: 35397545
Thanks pratima_mcs for your help, just needed more information.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question