开发者

submit multiple rows at a time mysql

开发者 https://www.devze.com 2023-02-25 01:42 出处:网络
i have a php generated form: <form action=\'step2.php\' method=\"post\" name=\'frm<? echo $socialid; ?>\' id=\"frm_step2\">

i have a php generated form:

 <form action='step2.php' method="post" name='frm<? echo $socialid; ?>' id="frm_step2">
       <?
      $result = mysql_query("SELECT * FROM socials WHERE ne开发者_如何学运维twork not in (SELECT network FROM networks WHERE user='$_SESSION[user_id]') ");

while($socialrow = mysql_fetch_assoc($result)){

    $socialid=$socialrow['id'];
    $socialnet=$socialrow['network'];
    ?>
   <a href="#" class="edit_<? echo $socialnet;?>"><img src="smallicons/<? echo $socialnet;?>.png" width="30" alt="<? echo $socialnet;?>" /></a>
    <div class="table_<? echo $socialnet;?>">the full url to your <? echo $socialnet;?> profile:<br />
    <input type='hidden' value='<? echo $socialnet;?>' name='network'/>
     <input type='text' name='urltonet'/> <br/>
    </div>

<?
}
    ?>
  <br />  <input type='submit' value='enter' />
  </form>  

basicly for every social network in the database it creates a form where the user needs to fill in their url to their profile so if the user still has to fill in 2 network urls, it will show two forms , one for each with one submit button

so if the user fills in both text boxes it will need to insert these values in the same database

any idea or help on how to insert these values please? below my database:

CREATE TABLE IF NOT EXISTS `networks` (
`user` int(30) NOT NULL,
`network` varchar(30) NOT NULL,
`username` varchar(30) NOT NULL default 'not known',
`url` varchar(300) NOT NULL,
`user_name` varchar(30) NOT NULL,
`netid` int(11) NOT NULL auto_increment,
PRIMARY KEY (`netid`),
UNIQUE KEY `netid` (`netid`),
UNIQUE KEY `netid_2` (`netid`),
UNIQUE KEY `netid_3` (`netid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=239 ;


as far as syntax goes it's you can use this, somehow i have feeling that is not what you wnat to know

insert into networks (user,network,url) values (1,'network1','username1'), (1,'network2','title2')


The trick on SQL Server and Oracle is to use union all

INSERT INTO MyTable (FirstCol, SecondCol)
SELECT 'First' ,1
UNION ALL
SELECT 'Second' ,2
UNION ALL
SELECT 'Third' ,3
UNION ALL
SELECT 'Fourth' ,4
UNION ALL
SELECT 'Fifth' ,5

I guess this would also work on MySQL

0

精彩评论

暂无评论...
验证码 换一张
取 消