-4

I uploaded a php file to my server and I got this error:

Parse error: syntax error, unexpected T_STRING in /www/zzl.org/m/a/d/madebytheo/htdocs/cms/index.php on line 3

Here is line three:

mysql_connect (localhost, password, username) or die (mysql_error());

Any idea what's wrong?

EDIT It turned out to be the lack of quotes.

codedude
  • 6,244
  • 14
  • 63
  • 99
  • Are `localhost`, `password` and `username` variables? are they strings? – yan Jul 26 '11 at 00:35
  • 3
    How are we to know, without any context? You need to show us the preceding lines, also. Ideally, narrow your problem down to a couple of lines of code that constitute a full program, and show us that. (More than likely, you will find the problem on your own by doing this; this is known as _debugging_.) – Lightness Races in Orbit Jul 26 '11 at 00:35
  • they aren't constants but rather I just substituted the words password and username for the actual password and usernanme. – codedude Jul 26 '11 at 01:07

2 Answers2

1

Ussually that kind of error is because some trivial typo. In this case, if the above code is your actual code, then you should use double quote to wrap localhost, password and username.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
toopay
  • 1,635
  • 11
  • 18
  • Actually, he should use single quotes. Unless they are variables (in which, he is then missing $ signs), there is no reason to have double quotes - its just inefficient. – Chris Jul 26 '11 at 00:47
  • 2
    @Chris: It will make hardly a blind bit of difference. Quit trying to micro-optimise. – Lightness Races in Orbit Jul 26 '11 at 00:50
  • I agree that it won't make a difference here, but why teach poor programming practices? If codedude goes on to make a huge application that deals with strings (or works for a company that relies heavily on efficient and speedy execution), it could have a very large effect (from experience). – Chris Jul 26 '11 at 01:02
  • i'll try the single quotes and see if the error disappears – codedude Jul 26 '11 at 01:07
  • For anyone which works for years in large project with a group of developer teams, hear someone which try to related trivial stuff like double quotes/single quotes with high performance application is really...funny. – toopay Jul 26 '11 at 01:12
  • @Chris, If you give yourself more time, to understand what I said, before hastily responded in part that may makes you feel offended, then you will realize that there is no single thing about your statement, which I rejected, of your the most utter, most ultimate and comment-of-the-century-super-duper conclusion that emerged from you about the Single Quoted vs Double Quoted. Referencing your link, just prove what i said : `Concatenation vs. interpolation is meaningless (in real world performance) if your database queries are poorly written or you aren't using any kind of caching scheme`. – toopay Jul 26 '11 at 09:23
0

Dollar signs(?) are missing.

mysql_connect($localhost, $password, $username) or die(mysql_error());
shinkou
  • 5,138
  • 1
  • 22
  • 32