mysql 一次提交多行
我有一个 php 生成的表单:
<form action='step2.php' method="post" name='frm<? echo $socialid; ?>' id="frm_step2">
<?
$result = mysql_query("SELECT * FROM socials WHERE network 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>
基本上,对于数据库中的每个社交网络,它都会创建一个表单,用户需要在其中填写其个人资料的 url 因此,如果用户仍然需要填写 2 个网络 url,它将显示两个表单,每个表单有一个提交按钮,
因此,如果用户填写两个文本框,则需要将这些值插入同一个数据库中,
任何想法或帮助请问如何插入这些值? 在我的数据库下面:
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 ;
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 network 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 ;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就语法而言,您可以使用它,不知怎的,我感觉这不是您想要知道的
as far as syntax goes it's you can use this, somehow i have feeling that is not what you wnat to know
SQL Server 和 Oracle 上的技巧是使用
union all
我想这也适用于 MySQL
The trick on SQL Server and Oracle is to use
union all
I guess this would also work on MySQL