MySQL/PHP Syntax Error

Running  PHP/5.3.1 MySQL client version: 5.1.41  under XAMPP 1.7.3:

Can't figure out what is wrong with the syntax in the attached code (adapted from an example in a PHP book).  Code is attached.

Error (pasted from browser output):
------------------------------

connecting to MySQL
inserting data into table: playeridlist
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 'VALUES (2, 'Fred', 'a', 'Flintstone'), VALUES (3, 'Donald', 'a', 'Duck')' at line 1

--------------------------------------------

Any ideas?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
// connect to:  MySQL
echo "connecting to MySQL";
echo "<br>";
$connect = mysql_connect ("localhost", "root", "") 
	or die ("wasn't able to connect to MySQL");

// ensure "players" database is current one
mysql_select_db ("players2");

// insert data into table "playeridlist"
echo "inserting data into table:  playeridlist";
echo "<br>";
$insert = "INSERT INTO playeridlist (player_id, player_firstname, player_middleinitial, player_lastname) " .
			"VALUES (1, 'John', 'a', 'Smith'), " .
			"VALUES (2, 'Fred', 'a', 'Flintstone'), " .
			"VALUES (3, 'Donald', 'a', 'Duck')";

$results = mysql_query($insert)
	or die (mysql_error());

// insert data into table "position"
echo "inserting data into table:  position";
echo "<br>";
$posns = "INSERT INTO position (position_id, position_labelabbr) " .
			"VALUES (1, 'DB'), " .
			"VALUES (2, 'WR'), " .
			"VALUES (3, 'RB')";

$results = mysql_query($posns)
	or die (mysql_error());

echo "Players data successfully entered.";
?>

</body>
</html>

Open in new window

qengAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hugh McCurdyCommented:
Try not repeating VALUES

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
0
Hugh McCurdyCommented:
$insert = "INSERT INTO playeridlist (player_id, player_firstname, player_middleinitial, player_lastname) " .
                  "VALUES (1, 'John', 'a', 'Smith'), " .
                  "(2, 'Fred', 'a', 'Flintstone'), " .
                  "(3, 'Donald', 'a', 'Duck')";

I'm not sure this is the problem but it's my first guess.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
qengAuthor Commented:
Will try but this will get difficult to manage.  This is just an example I'm troubleshooting.  I will have approximately 40 lines of values to add once this works (I'll ultimately do this more elegantly but have to get something out for now).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.