| | |
inserting checkbox values in mysql +PHP
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2008
Posts: 41
Reputation:
Solved Threads: 0
I am new to PHP or just not good at it lol, I have been trying to insert checkbox elements into a mysql database.
I have a table called Team with two collumns.
Id int not null auto increment PK
team varchar 30 not null
<?
<body><form action="insert.php" method="post">
select team:
<input type="checkbox" value="AR" NAME="team[]">:Argentina
<input type="checkbox" value="PL" NAME="team[]">
pain
<input type="checkbox" value="GB" NAME="team[]">:Holland
<input type="checkbox" value="FR" NAME="team[]">:France
<br>
<input name="confirm" type=submit id="confirm" style='border:1px solid #000000;font-family:Verdana, Arial, Helvetica, sans-serif ;font-size:9px;' value='Confirm'>
</body>
</form>
?>
This is the insert.php
<?php
$con = mysql_connect("localhost","****","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
if (!$id) {
$id= null;
}
<?
if(isset($_POST['team']))
{
$team = 1;
$insert=mysql_query("
INSERT INTO team('team') VALUES ('" . $team. ");
?>
Parse error: syntax error, unexpected '<' in C:\wamp\www\examples\insert.php on line 10
Any help or suggestions will be much appreciated.
I have a table called Team with two collumns.
Id int not null auto increment PK
team varchar 30 not null
<?
<body><form action="insert.php" method="post">
select team:
<input type="checkbox" value="AR" NAME="team[]">:Argentina
<input type="checkbox" value="PL" NAME="team[]">
pain<input type="checkbox" value="GB" NAME="team[]">:Holland
<input type="checkbox" value="FR" NAME="team[]">:France
<br>
<input name="confirm" type=submit id="confirm" style='border:1px solid #000000;font-family:Verdana, Arial, Helvetica, sans-serif ;font-size:9px;' value='Confirm'>
</body>
</form>
?>
This is the insert.php
<?php
$con = mysql_connect("localhost","****","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
if (!$id) {
$id= null;
}
<?
if(isset($_POST['team']))
{
$team = 1;
$insert=mysql_query("
INSERT INTO team('team') VALUES ('" . $team. ");
?>
Parse error: syntax error, unexpected '<' in C:\wamp\www\examples\insert.php on line 10
Any help or suggestions will be much appreciated.
php Syntax (Toggle Plain Text)
<?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 <br /> <input type="checkbox" name="team[]" value="GE"> Germany <br /> <input type="checkbox" name="team[]" value="BR"> Brazil <br /> <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.
Last edited by nav33n; Feb 8th, 2008 at 9:24 am.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 41
Reputation:
Solved Threads: 0
<html>
<body>
<form method="post" action="chk123.php">
<input type="checkbox" name="team[]" value="AG"> Argentina <br />
<input type="checkbox" name="team[]" value="GE"> Germany <br />
<input type="checkbox" name="team[]" value="BR"> Brazil <br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
<?php
$con = mysql_connect("localhost","root","****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
if(isset($_POST['team']))
{ foreach($_POST['team'] as $value){
$insert=mysql_query("INSERT INTO team('team')
VALUES ('$value')");
}
}
?>
I am getting the error below, whats wrong???
Parse error: syntax error, unexpected $end in C:\wamp\www\examples\chk123.php on line 13
<body>
<form method="post" action="chk123.php">
<input type="checkbox" name="team[]" value="AG"> Argentina <br />
<input type="checkbox" name="team[]" value="GE"> Germany <br />
<input type="checkbox" name="team[]" value="BR"> Brazil <br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
<?php
$con = mysql_connect("localhost","root","****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
if(isset($_POST['team']))
{ foreach($_POST['team'] as $value){
$insert=mysql_query("INSERT INTO team('team')
VALUES ('$value')");
}
}
?>
I am getting the error below, whats wrong???
Parse error: syntax error, unexpected $end in C:\wamp\www\examples\chk123.php on line 13
php Syntax (Toggle Plain Text)
$insert="INSERT INTO team('team') VALUES ('$value')"; echo $insert; mysql_query($insert);
mysql_query($insert) or die(mysql_error()); to know what is the error. Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 41
Reputation:
Solved Threads: 0
Hi, i have tried this but doesn't return anything.
I'm Wondering whether my table design in mysql is incorrect.
I have only two collumns, one to store the ID and one to store the team.
Table Team
id Int(11) Not Null auto_increment
team varchar(30) Not Null
<?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=mysql_query("INSERT INTO team('team')
VALUES ('$value')");
}
}
echo $insert;mysql_query($insert);
?>
I'm Wondering whether my table design in mysql is incorrect.
I have only two collumns, one to store the ID and one to store the team.
Table Team
id Int(11) Not Null auto_increment
team varchar(30) Not Null
<?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=mysql_query("INSERT INTO team('team')
VALUES ('$value')");
}
}
echo $insert;mysql_query($insert);
?>
![]() |
Similar Threads
- Variable passed to each() is not an array (PHP)
- How to delete using checkboxes (PHP)
- Storing dynamic form values in Arrays for display & insert (PHP)
Other Threads in the PHP Forum
- Previous Thread: problem in deleting
- Next Thread: Cookies problem - not working
| Thread Tools | Search this Thread |
301 access apache api array beginner binary broken button cakephp checkbox class clean cms code countingeverycharactersfromastring crack cron curl database date decode directory display dissertation dropdown dynamic echo email error fairness file files folder form forms function functions google href htaccess html image include insert integration ip javascript joomla limit link login mail match md5 menu methods mlm multiple mysql newsletters oop pageing pagerank paypal pdf php problem protocol query radio random recursion remote script search secure server sessions simple sms soap source space spam sql syntax system table tutorial update upload url validator variable video virus votedown web youtube






