I have a database with 3. The first tables are named "periorismoi" and "programmata". The first one has 2 colums ("Auxon" , "Title") and the second one 3 ("Auxon" , "Name" , "Periorismoi"). I made a page with a form of adding a new 'programmata'. In the column "Name" a text will be added from the form and in the column "Periorismoi" a name will be added from a checkbox (from the same form). The checkbox names will derive from the table "periorismoi". I am giving you the page of the form and then the Insert to the database (action) page. It doesn't work. Maybe a server error ? It used to work before I put the checkboxes in the form. Note that Periorismoi is different than periorismoi.
<form action='Insert.php' method="post" enctype='multipart/form-data' periorismoi="periorismoi">
<textarea name="title" placeholder="Πρόγραμμα" rows=\"1\" cols=\"50\"></textarea>
<?php
$link = mysql_connect('localhost', 'student1905','123456');
mysql_select_db('student1905');
$q="select * FROM periorismoi";
$result=mysql_query($q);
$counts=mysql_num_rows($result);
for ( $i = 0; $i < $counts; ++$i ) {
$row = mysql_fetch_array( $result );
if(isset($row[ "Title" ]))
{$Title= $row[ "Title" ];
}
?>
<input type="checkbox" name="<?php echo "periorismoi$i"; ?>" value=""<?php echo $row['Title']; ?>""><?php echo "$Title";?> <br>
<?php
}
?>
Insert.php page:
<?php
$link = mysql_connect('localhost', 'student1905','123456');
mysql_select_db('student1905');
$title= trim($_POST["title"]);
if(!$link)
{
die('Could not connect: ' . mysql_error());
}
else {
if(strlen($title) == 0)
{
header("Location:Index.php");
}
else
{
mysql_query("SET NAMES utf8");
$periorismoi = implode(',', $_POST['periorismoi']);
$len = sizeof($periorismoi);
for($i=0; $i<$len;$i++){
$sql="INSERT INTO programmata (Auxon,Title,Periorismoi) VALUES ('','$title','$periorismoi')";
mysql_query($sql);
}
header("Location:Index.php"); ;
}
}
?>