•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,885 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,364 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 6186 | Replies: 66
![]() |
| |
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Rep Power: 1
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.
•
•
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation:
Rep Power: 3
Solved Threads: 68
what's the line 10? I think you have left a bracket missing.
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
http://ryantetek.wordpress.com
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
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 8:24 am.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Rep Power: 1
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
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
missing } after die function.
Last edited by nav33n : Feb 8th, 2008 at 11:07 am.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
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. Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Rep Power: 1
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);
?>
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- 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



Hybrid Mode