2015-10-11 48 views
-4

请问我想知道成功执行下面的代码的可能性... 如果有可能实现,请有人可以帮助我,并让我度过我得到它的位置错误。从提交表格中插入多行的表格

......认为我是一个绿色的号角在这里

<!---HTML file---> 
 
<form name='myform' action='test.php' method='post'> 
 
<input type='text' name='fname' value='John' /> 
 
<input type='text' name='phone' value='+254 ********' /> 
 

 
<input type='text' name='fname' value='Jane' /> 
 
<input type='text' name='phone' value='+254 ********' /> 
 

 
<input type='text' name='fname' value='Chris' /> 
 
<input type='text' name='phone' value='+254 *********' /> 
 

 
<input type='text' name='fname' value='Solo' /> 
 
<input type='text' name='phone' value='+254 *********' /> 
 

 

 
<input type='submit' value='I wish to insert all the four sets of records at once' /> 
 
</form>

$fname = trim(mysql_real_escape_string($_POST["fname"])); 

$phone = trim(mysql_real_escape_string($_POST["phone"])); 

$results = mysql_query("INSERT INTO mytable (id, fname, phone) 

VALUES 
('', '$fname', '$phone'), 
('', '$fname', '$phone'), 
('', '$fname', '$phone'), 
('', '$fname', '$phone')"); 
+0

在互联网上有很多的教程,甚至在这个网站上。做一个搜索“快速入门PHP Mysql教程” – NiGhTHawK

回答

0

声明所有输入名称数组如

<input type='text' name='fname[]' value='John' /> 
    <input type='text' name='phone[]' value='+254   ********' /> 

在PHP文件我们可以使用for循环获取所有的fname,电话