RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 8085 | Replies: 66 | Thread Tools  Display Modes
Reply
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 9
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: inserting checkbox values in mysql +PHP

  #11  
Feb 11th, 2008
  1. <?php
  2. $con = mysql_connect("localhost","root","talk21");
  3. if (!$con) {
  4. die('Could not connect: ' . mysql_error());
  5. }
  6. if(isset($_POST['team'])) { foreach($_POST['team'] as $value) {
  7. $insert="INSERT INTO team ('team') VALUES ('$value')";
  8. echo $insert;
  9. mysql_query($insert);
  10. }
  11. }
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 !
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: 39
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

  #12  
Feb 11th, 2008
I tried the query it prints "INSERT INTO team ('team') VALUES ('BR')" correctly however it still doesnt store the value into the database, I even selected mysql_select_db("lastr", $con);$sql= the database still not working.

thank you for all your responses by da way.







<?php
$con = mysql_connect("localhost","root","talk21");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if(isset($_POST['team']))
{ foreach($_POST['team'] as $value) {
mysql_select_db("lastr", $con);$sql= $insert="INSERT INTO team ('team')
VALUES ('$value')";echo $insert;mysql_query($insert);
}
}

?>
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 9
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: inserting checkbox values in mysql +PHP

  #13  
Feb 11th, 2008
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.
  1. $query="select * from tablename";
  2. 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.
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: 39
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

  #14  
Feb 11th, 2008
I have tried it with this function "mysql_query($query) or die(mysql_error());"

there is no error and nothing is still being inserted into the database .




<?php
$con = mysql_connect("localhost","root","talk21");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if(isset($_POST['team']))
{ foreach($_POST['team'] as $value) {
mysql_select_db("lastr", $con);$sql= $insert="INSERT INTO team ('team')
VALUES ('$value')";echo $insert;mysql_query($insert);
}
}


$query="select * from team";mysql_query($query) or die(mysql_error());

?>
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 9
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: inserting checkbox values in mysql +PHP

  #15  
Feb 11th, 2008
Okay! Take out 'team' and put team. ie.,
$insert="INSERT INTO team (team)
VALUES ('$value')";

Tellme if it works.
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: 39
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

  #16  
Feb 11th, 2008
Still the same, Nothing going into the database, maybe should insert into id aswell.


<?php
$con = mysql_connect("localhost","root","talk21");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

if(isset($_POST['team']))
{ foreach($_POST['team'] as $value) {
mysql_select_db("lastr", $con);$sql= $insert="INSERT INTO team. ('team')
VALUES ('$value')";echo $insert;mysql_query($insert);
}
}


$query="select * from team";mysql_query($query) or die(mysql_error());
?>
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 9
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: inserting checkbox values in mysql +PHP

  #17  
Feb 11th, 2008
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 ?
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: 39
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

  #18  
Feb 11th, 2008
INSERT INTO team ('team') VALUES ('GE')INSERT INTO team ('team') VALUES ('BR')

the id is set to auto_increment, when i run the query on phpadmin this is the error.

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''team') VALUES ('GE')INSERT INTO team ('team') VALUES ('BR')' at line 1
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 9
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: inserting checkbox values in mysql +PHP

  #19  
Feb 11th, 2008
That's what I was talking about.
  1.  
  2. <?php
  3. $con = mysql_connect("localhost","root","talk21");
  4. if (!$con)
  5. {
  6. die('Could not connect: ' . mysql_error());
  7. }
  8. mysql_select_db("lastr");
  9.  
  10. if(isset($_POST['team']))
  11. {
  12. foreach($_POST['team'] as $value) {
  13. $insert="INSERT INTO team (team) VALUES ('$value')";
  14. mysql_query($insert);
  15. }
  16. }
  17. ?>

This will definitely work.

P.S: Next time you post your code, please post it within [code] tags.
Last edited by nav33n : Feb 11th, 2008 at 1:09 pm.
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: 39
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

  #20  
Feb 12th, 2008
Great, many thanks for your help . say if i wanted to do a dynamic table in mysql to insert the checkbox values from is there any threads you could point me to for example or help.
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)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 6:29 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC