I am trying to write a PHP script to connect to a database I have created in WAMP Server 2.0 but no matter what I do I keep getting the same error message:
Parse error: parse error in C:\wamp\www\database.php on line 5
I have looked at this for over an hour now and I cannot see what in the world is the issue here. Maybe you can help me.
This is the code I am trying to use

<?php
$con = mysql_connect("localhost","test","password");
if (!$con) die 'could not connect: . mysql_error());}
mysql_select_db("Directory");
mysql_query("INSERT INTO Directory('lname','fname','address','city','state','zipcode','areacode','telephone')
VALUES ('newlname','newfname','newaddress','newzipcode','newareacode','newtelephone');");
?>
<a href="Lloyd_Project7.html>Back to directory</a>;

and as I said I cannot see anything that would be causing a parse error on line 5 or anywhere for that matter:icon_frown:
Any advice would be greatly appreciated!!
Zack

Well, you have 2 brackets on the left and only 1 on the right... on line 5.

... And the last one is on line 6. My bad :)

I am trying to write a PHP script to connect to a database I have created in WAMP Server 2.0 but no matter what I do I keep getting the same error message:
Parse error: parse error in C:\wamp\www\database.php on line 5
I have looked at this for over an hour now and I cannot see what in the world is the issue here. Maybe you can help me.
This is the code I am trying to use

<?php
$con = mysql_connect("localhost","test","password");
if (!$con) die 'could not connect: . mysql_error());}
mysql_select_db("Directory");
mysql_query("INSERT INTO Directory('lname','fname','address','city','state','zipcode','areacode','telephone')
VALUES ('newlname','newfname','newaddress','newzipcode','newareacode','newtelephone');");
?>
<a href="Lloyd_Project7.html>Back to directory</a>;

and as I said I cannot see anything that would be causing a parse error on line 5 or anywhere for that matter:icon_frown:
Any advice would be greatly appreciated!!
Zack

I don't know if this is your only problem but field names (lname, fname ect) do not need ''s also if zip, area code and telephone are numbers and are stored as such, you do not use '' either. Oh and also the end of the query does NOT need a semicolon (;)

I hope this helps.

Oh, it's the semicolon at the end of line 6 :D One to many...

I don't know if this is your only problem but field names (lname, fname ect) do not need ''s also if zip, area code and telephone are numbers and are stored as such, you do not use '' either. Oh and also the end of the query does NOT need a semicolon (;)

I hope this helps.

I am not exactly sure what you mean by field names that do not need ''s.
I removed the 's around the names I had as such

mysql_query("INSERT INTO Directory(lname,fname,address,city,state,zipcode,areacode,telephone)
VALUES ('newlname','newfname','newaddress','newzipcode','newareacode','newtelephone')");

but am still getting a parse error for line 5.
I also removed one of the ;s on line 6 as above but that did not help either.:confused:
and now i am getting this error:
Parse error: parse error in C:\wamp\www\database.php on line 6
?? Did I miss something??:?: Or did I remove the wrong ;??

are areacode zipcode and telephone defined as numbers in your table?

here's a query I wrote for a program I was working on:

$query = "INSERT INTO subjects (menu_name, position, visible) VALUES ('About Us', 1, 0)";
mysql_query($query, $connection); //the $connection is optional

menuName is the only varchar field the other 2 are numbers

Oh, it's the semicolon at the end of line 6 :D One to many...

This was my original line 6

VALUES ('newzipcode','newareacode','newtelephone');");

and I see that yes there are 2 semicolons at the end but which one should I remove, the one inside the parenthesis or the one at the end after the second parenthesis??:confused:
in other words should it look like this

VALUES ('newzipcode','newareacode','newtelephone')");

or this

VALUES ('newzipcode','newareacode','newtelephone');")

??
Could you please elaborate for me??

are areacode zipcode and telephone defined as numbers in your table?

here's a query I wrote for a program I was working on:

$query = "INSERT INTO subjects (menu_name, position, visible) VALUES ('About Us', 1, 0)";
mysql_query($query, $connection); //the $connection is optional

menuName is the only varchar field the other 2 are numbers

Okay I think I see what your are saying about varchar and int being used in queries but that does not solve my parse error issue and if I change that to be correct it still gives me a parse error on line 5.:(

dumb question for you: did you already make the table with those fields?

anyways try

mysql_query("INSERT INTO Directory(lname,fname,address,city,state,zipcode,areacode,telephone)
VALUES ('newlname','newfname','newaddress', 'cityname','somestate',90210,123,5555555)");


I just realized, in your initial post you were missing a few arguments, you were missing city and state.

make sure varchars have single quotes ( 'example' ) and numbers do not.

dumb question for you: did you already make the table with those fields?

anyways try

mysql_query("INSERT INTO Directory(lname,fname,address,city,state,zipcode,areacode,telephone)
VALUES ('newlname','newfname','newaddress', 'cityname','somestate',90210,123,5555555)");


I just realized, in your initial post you were missing a few arguments, you were missing city and state.

make sure varchars have single quotes ( 'example' ) and numbers do not.

Yes I am trying to access an already created database which already has tables made in phpMyadmin on wamp server 2.0. Although since this is a project I am just starting on I suppose I could just make a new database to work with. Still after reading your code it seems that you believe there will be just a single entry to the database when in fact it will be many entries and so i can not just put in an arbitrary state, zipcode, or areacode with phone number.:confused: Those values will be tables in the database set to receive integers. Thank you for the pointers about the quotes though, I will remember that but I still have a lot to do before I am finished here!!

Here's my original query from my previous example in case you missed that in your code.

$query = "INSERT INTO subjects ( menu_name, position, visible ) VALUES ( '{$menuName}', {$position}, {$visible} )";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.