<?php
if(isset($_POST['team']))
{
foreach($_POST['team'] as $value){
$insert=mysql_query("INSERT INTO team('team') VALUES ('$value')");
}
}
?>
<html>
<body>
<form method="post" action="chk123.php">
<input type="checkbox" name="team[]" value="AG"> Argentina
<input type="checkbox" name="team[]" value="GE"> Germany
<input type="checkbox" name="team[]" value="BR"> Brazil
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
There! That will work :)
Cheers,
Naveen
Edit: The error was because, you had opened php tag but you opened it again.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
missing } after die function.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
$insert="INSERT INTO team('team')
VALUES ('$value')";
echo $insert;
mysql_query($insert);
Print your query. Execute the same in phpmyadmin or mysql. Check what's the error. Or you can give, mysql_query($insert) or die(mysql_error()); to know what is the error.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
<?php
$con = mysql_connect("localhost","root","talk21");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
if(isset($_POST['team'])) { foreach($_POST['team'] as $value) {
$insert="INSERT INTO team ('team') VALUES ('$value')";
echo $insert;
mysql_query($insert);
}
}
Try this. It will print out the query. Execute it in phpmyadmin or mysql. I don't think your query or the table structure is wrong. Maybe the values of $_POST['team'] isn't being passed. Well, execute these queries and find out why its not inserting !
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
umm.. You don't have a mysql_select_db in your script. If it isn't inserting, use die function with mysql_error with your query. For eg.
$query="select * from tablename";
mysql_query($query) or die(mysql_error());
So, if there's any problem with your query, it will output the error message, which you can use to debug your query.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
Okay! Take out 'team' and put team. ie.,
$insert="INSERT INTO team (team)
VALUES ('$value')";
Tellme if it works.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
Umm.. is Id an auto-increment field ? What did echo $insert print ? Could you show us the statement ? Did you execute that statement in phpmyadmin/mysql ?
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
:) That's what I was talking about.
<?php
$con = mysql_connect("localhost","root","talk21");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("lastr");
if(isset($_POST['team']))
{
foreach($_POST['team'] as $value) {
$insert="INSERT INTO team (team) VALUES ('$value')";
mysql_query($insert);
}
}
?>
This will definitely work. :)
P.S: Next time you post your code, please post it within[code] tags.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356