0

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

在此处输入图像描述

<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>
4

1 回答 1

0

展开文本区域中的链接

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

循环链接并插入

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

别忘了逃跑...

于 2012-12-18T23:09:58.770 回答