User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 373,375 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 3,824 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: 4926 | Replies: 66
Reply
Join Date: Feb 2008
Posts: 37
Reputation: asadalim1 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
asadalim1 asadalim1 is offline Offline
Light Poster

inserting checkbox values in mysql +PHP

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 473
Reputation: ryan_vietnow is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 62
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro in Training

Re: inserting checkbox values in mysql +PHP

  #2  
Feb 8th, 2008
what's the line 10? I think you have left a bracket missing.
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is online now Online
Posting Sensei

Re: inserting checkbox values in mysql +PHP

  #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 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*
Reply With Quote  
Join Date: Feb 2008
Posts: 37
Reputation: asadalim1 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
asadalim1 asadalim1 is offline Offline
Light Poster

Re: inserting checkbox values in mysql +PHP

  #4  
Feb 8th, 2008
Thank you
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is online now Online
Posting Sensei

Re: inserting checkbox values in mysql +PHP

  #5  
Feb 8th, 2008
You are welcome!
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*
Reply With Quote  
Join Date: Feb 2008
Posts: 37
Reputation: asadalim1 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
asadalim1 asadalim1 is offline Offline
Light Poster

Re: inserting checkbox values in mysql +PHP

  #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  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is online now Online
Posting Sensei

Re: inserting checkbox values in mysql +PHP

  #7  
Feb 8th, 2008
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*
Reply With Quote  
Join Date: Feb 2008
Posts: 37
Reputation: asadalim1 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
asadalim1 asadalim1 is offline Offline
Light Poster

Re: inserting checkbox values in mysql +PHP

  #8  
Feb 8th, 2008
It processes, but nothing is stored in the Mysql, table
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is online now Online
Posting Sensei

Re: inserting checkbox values in mysql +PHP

  #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.
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*
Reply With Quote  
Join Date: Feb 2008
Posts: 37
Reputation: asadalim1 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
asadalim1 asadalim1 is offline Offline
Light Poster

Re: inserting checkbox values in mysql +PHP

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 3:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC