Please support our PHP advertiser: Lunarpages PHP Web Hosting
![]() |
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 9
Solved Threads: 240
php Syntax (Toggle Plain Text)
<?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="INSERT INTO team ('team') VALUES ('$value')"; echo $insert; mysql_query($insert); } }
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: 39
Reputation:
Rep Power: 1
Solved Threads: 0
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);
}
}
?>
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);
}
}
?>
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 9
Solved Threads: 240
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.
So, if there's any problem with your query, it will output the error message, which you can use to debug your query.
php Syntax (Toggle Plain Text)
$query="select * from tablename"; mysql_query($query) or die(mysql_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: 39
Reputation:
Rep Power: 1
Solved Threads: 0
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());
?>
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());
?>
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 9
Solved Threads: 240
Okay! Take out 'team' and put team. ie.,
Tellme if it works.
$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*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 39
Reputation:
Rep Power: 1
Solved Threads: 0
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());
?>
<?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());
?>
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 9
Solved Threads: 240
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*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 39
Reputation:
Rep Power: 1
Solved Threads: 0
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
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
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 9
Solved Threads: 240
That's what I was talking about. php Syntax (Toggle Plain Text)
<?php $con = mysql_connect("localhost","root","talk21"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("lastr"); if(isset($_POST['team'])) { foreach($_POST['team'] as $value) { $insert="INSERT INTO team (team) VALUES ('$value')"; mysql_query($insert); } } ?>
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*
*PM asking for help will be ignored*
![]() |
Similar Threads
Other Threads in the PHP Forum
- 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
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode