Funkcja explode - dodawanie rekordów do bazy


(Patrol) #1

Witam!

Mam taki kod:

<?php

 $querycodesforshop=mysql_query('SELECT * FROM codesforlottery1');

 $rowcodesforshop=mysql_num_rows($querycodesforshop);


if(isset($_POST['submitcodesforshop']))

{

	$explodecodesforshop=explode("\n",$_POST['codesforshop']);

	$codeforshop=count($explodecodesforshop);

	for($i=0;$i<$codeforshop;$i++) 

		{

		mysql_query('INSERT INTO codes$_POST[name] VALUES ('NULL','$explodecodesforshop[$i]','".$_POST['available']."')');

		}

	echo '
Kody zostały dodane!';

}

?>

Niestety nie działa on poprawnie bo wywali mi:

Linia 15 to linia pod zapytaniem do bazy.


(adpawl) #2
<?php

$querycodesforshop=mysql_query('SELECT * FROM codesforlottery1');

$rowcodesforshop=mysql_num_rows($querycodesforshop);


if(isset($_POST['submitcodesforshop']))

{

   $explodecodesforshop=explode("\n",$_POST['codesforshop']);

   $codeforshop=count($explodecodesforshop);

   $cname='codes'.$_POST['name'];

   $av=$_POST['available'];   

   for($i=0;$i<$codeforshop;$i++) 

      {

      mysql_query("INSERT INTO '$cname' VALUES ('NULL','$explodecodesforshop[$i]','$av')");

      }

   echo '
Kody zostały dodane!';

}

?>