HOME       >>       Programming

Php Error


Okey, so I got this error: Parse error: syntax error, unexpected T_STRING in C:wampwwwragnhildprosjekt1visinnlegg.php on line 48


I've read about T_STRING but I cant solve this problem. Here is the code:


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO kommentar (tittel, navn, tekst, tidsstempel, innleggid) VALUES ( %s, %s, %s, NOW(), %s)' GetSQLValueString($_POST['tittel'], "text"), GetSQLValueString($_POST['navn'], "text"), GetSQLValueString($_POST['tekst'], "text"), GetSQLValueString($_GET['innleggid'], "int") );

and line 48 is: GetSQLValueString($_POST['tittel'], "text"),

Can somebody please help me out with this?


The problem is actually on line 47: you open the "INSERT INTO..." with a double quote, but close it with a single quote. And the PHP interpreter thinks the single quote is a part of the string started at the beginning, and that that string is continuing onto line 48... now when you finally have a double string, "text", it thinks that's where the string ends, and it doesn't know what to do with the line that says "text", since you would need a closing parentheses of the sprintf, or a comma for the next parameter, before you can make any new assertions like that: and that's why you get that error. Oh, and just for the future, to make sure you don't make the same mistake again, you should've been able to figure all this out simply by looking at the fact that the GetSQLValueString is green instead of black in the code parser previewer on this forum.


You have got a problem with the quotes in the code snippet that you have posted. If you are using Notepad or a text editor that does not automatically create the closing quote for you when you type the opening quote, I would suggest that you try a different PHP editor. NuSphere's PhpEd is good stuff. Komodo makes a good IDE and editor too, but they do have stability issues that they are trying to work out - when they do, they'll have a good product to offer. Notepad++ and many other free editors, will show you the closing quote when you click on the opening quote or vice-versa. Try different source code editors and see what works for your coding style.


Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.