2016-12-09 11 views
-3

繰り返し挿入値カートの

<?php 
 
include("config.php"); 
 
$cart=$_GET['cart']; 
 
$numberofcart=$_GET['numberofcart']; 
 
if ($cart) { 
 
mysql_query("INSERT INTO trade (cart,price) values('$cart','150LE')"); 
 

 
} 
 
?> 
 

 

 
<form action="index.php" method="GET"> 
 
    <input type="text" name="cart" /> 
 
    <input type="text" name="numberofcart" /> 
 
    <input type="submit" /> 
 
</form>
数= MySQLの IDカート価格
1ペン150LE
2ペン150LE
3ペン150LE

iwantこのような繰り返しの数

+0

「mysql_ *」を使用して停止します。 'mysqli_ *'や 'PDO'を使う –

+1

そして[How To Ask](http://stackoverflow.com/help/how-to-ask)をご覧ください。 –

+0

あなたの質問については、ループ – Mogzol

答えて

0
<?php 
include("config.php"); 
$cart=$_POST['cart']; 
$numberofcart=$_POST['numberofcart']; 
$values =''; 

if ($cart !=='' && $numberofcart !=='') { 
    for($i=0;$i<$numberofcart;$i++){ 
     $values .= "('$cart','150LE'),"; 
    } 
    $values = trim($values,','); 
    mysql_query("INSERT INTO trade (cart,price) values $values");// good to change connection code in file according to mysqli_* standards 
}else{ 
    echo "form field are required"; 
} 
?> 


<form action="index.php" method="POST"> 
    <input type="text" name="cart" /> 
    <input type="text" name="numberofcart" /> 
    <input type="submit" /> 
</form> 

例: - https://eval.in/694166

+0

ありがとうございました コードから$ connectionを削除 –