inserting checkbox values in mysql +PHP

Reply

Join Date: Feb 2008
Posts: 41
Reputation: asadalim1 is an unknown quantity at this point 
Solved Threads: 0
asadalim1 asadalim1 is offline Offline
Light Poster

inserting checkbox values in mysql +PHP

 
0
  #1
Feb 8th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 561
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: inserting checkbox values in mysql +PHP

 
0
  #2
Feb 8th, 2008
what's the line 10? I think you have left a bracket missing.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: inserting checkbox values in mysql +PHP

 
0
  #3
Feb 8th, 2008
  1. <?php
  2. if(isset($_POST['team']))
  3. {
  4. foreach($_POST['team'] as $value){
  5. $insert=mysql_query("INSERT INTO team('team') VALUES ('$value')");
  6. }
  7. }
  8. ?>
  9. <html>
  10. <body>
  11. <form method="post" action="chk123.php">
  12. <input type="checkbox" name="team[]" value="AG"> Argentina <br />
  13. <input type="checkbox" name="team[]" value="GE"> Germany <br />
  14. <input type="checkbox" name="team[]" value="BR"> Brazil <br />
  15. <input type="submit" name="submit" value="submit">
  16. </form>
  17. </body>
  18. </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*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 41
Reputation: asadalim1 is an unknown quantity at this point 
Solved Threads: 0
asadalim1 asadalim1 is offline Offline
Light Poster

Re: inserting checkbox values in mysql +PHP

 
0
  #4
Feb 8th, 2008
Thank you
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: inserting checkbox values in mysql +PHP

 
0
  #5
Feb 8th, 2008
You are welcome!
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 41
Reputation: asadalim1 is an unknown quantity at this point 
Solved Threads: 0
asadalim1 asadalim1 is offline Offline
Light Poster

Re: inserting checkbox values in mysql +PHP

 
0
  #6
Feb 8th, 2008
<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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: inserting checkbox values in mysql +PHP

 
0
  #7
Feb 8th, 2008
missing } after die function.
Last edited by nav33n; Feb 8th, 2008 at 12:07 pm.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 41
Reputation: asadalim1 is an unknown quantity at this point 
Solved Threads: 0
asadalim1 asadalim1 is offline Offline
Light Poster

Re: inserting checkbox values in mysql +PHP

 
0
  #8
Feb 8th, 2008
It processes, but nothing is stored in the Mysql, table
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: inserting checkbox values in mysql +PHP

 
0
  #9
Feb 8th, 2008
  1. $insert="INSERT INTO team('team')
  2. VALUES ('$value')";
  3. echo $insert;
  4. 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.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 41
Reputation: asadalim1 is an unknown quantity at this point 
Solved Threads: 0
asadalim1 asadalim1 is offline Offline
Light Poster

Re: inserting checkbox values in mysql +PHP

 
0
  #10
Feb 11th, 2008
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);

?>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC