使用php在数据库中添加multirows

时间:2012-12-18 23:03:00

标签: php mysql

我必须在数据库中添加许多具有相同特征的链接(链接类型,国家,作者,项目)。例如,我想在我的数据库中添加6个链接 - 6个(见图像),一次全部。请帮帮我。

enter image description here

<html>
<head><title>Add values to DataBase</title></head>
    <body>
        <form name="input" action="" method="post">
            <table>
                    <tr>
                    <td>
                <b>Link Type: <br><input type="text" name="LinkType"><br>
                    </td>
                    <td>
                <b>Country: <br><input type="text" name="Country"><br>
                    </td>
                    </tr>
                    <tr>
                    <td>
                <b>Author: <br><input type="text" name="Author"><br>
                    </td>
                    <td>
                <b>Project: <br><input type="text" name="Project"><br>
                    </td>
                    </tr>
            </table>
                <b>Links:</b><br>
                    <textarea rows="20" cols="80" name='Link'>
                    </textarea><br>
                    <input type="submit" onclick="Confirmare()" name="introdu" value="Exporta">
        </form> 
    </body>
</html>

<?PHP

    error_reporting(E_ALL & ~E_NOTICE);
    mysql_connect("localhost", "root", "pechea.com") or die(mysql_error());
    mysql_select_db("repdb") or die(mysql_error());

    $Link=$_POST['Link'];
    $LinkType=$_POST['LinkType'];
    $Project=$_POST['Project'];
    $Date=$_POST['Date'];
    $Country=$_POST['Country'];
    $Author=$_POST['Author'];
    $Status=$_POST['Status'];




?>
<script type="text/javascript">
        function Confirmare()
        {
<?php
    mysql_query("INSERT INTO projects (Link, LinkType, Project, Date, Country, Author, Status)  
    VALUES ('".$Link."', '".$LinkType."', '".$Project."','".$Date."', '".$Country."', '".$Author."', '".$Status."') ")  or die(mysql_error());

?>
alert("Values Added in DB!");}
</script>

1 个答案:

答案 0 :(得分:0)

在textarea中爆炸链接

$links = explode("\n", $_POST['Link']);

循环链接并插入

foreach($links as $link) {
    mysql_query("INSERT ...");
}

别忘了逃避...