2012-12-18 2 views
1

동일한 특성 (링크 유형, 국가, 저자, 프로젝트)을 가진 많은 링크를 데이터베이스에 추가해야합니다. 예를 들어, 데이터베이스에 6 개의 링크 (6 개의 이미지)를 한꺼번에 추가하려고합니다. 제발 도와주세요.PHP를 사용하여 데이터베이스에 다중 행 추가

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> 

답변

0

링크 불구하고

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

루프 텍스트 영역에서 링크를 폭발

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

탈출하는 것을 잊지 마세요 ...

+2

그것은 일 삽입 ! 고마워! –

관련 문제