Page 1 of 1

New Comer, with a Question.

Posted: Thu Oct 17, 2002 8:18 pm
by Andy
Well, I'm trying to install a news value
'thing' and I'm the newbiest of newbies at running queries as you can get. Upon running, I get an error.

INSERT INTO setting (settingid,settinggroupid,title,varname,value,description,optioncode,displayorder) VALUES (NULL,2,'News','$news','','Insert forum news here...','textarea','7');


^^Thats^^ the quiery, and I get an error that says soemthing is wrong at the end of line one begining from $news. Help is appreciated.

possible solution

Posted: Thu Oct 17, 2002 8:35 pm
by phpScott
it is probalby trying to subsitiute $news with a value and can't.
It looks like you want to save $news as a literal and not its value.
Try escaping the $ like \$news.

this should escape the $ sign and save it as a literal.

the other thing you could do is strip of the $ and just save news as you know what the column is and can add the $ back when ever you need it as a variable.

of coure why are trying to save a variable name in your db anyway :?:

Posted: Fri Oct 18, 2002 3:46 am
by Wayne
By putting $news in single quotes it will not try and pass the variable $news with the result being it will try and insert $news as a string value into the record. either use double quotes "$news" or concatenate the string.

That might or might not be the problem, do you want to post the code and the actual error message so we can get a better idea.

Posted: Fri Oct 18, 2002 9:13 pm
by Andy
You have an error in your SQL syntax near '''News'',''$news'','''',''Insert forum news here...'',''textarea'',''7'')' at line 1

That's the error. I'll go try what you guys stated above.

EDIT:: Same problem. Tried "" and Tried the \ Before $.

Posted: Mon Oct 21, 2002 4:20 am
by twigletmac
If you're doing this through PHP:

Code: Select all

$sql = "INSERT INTO setting 
(settingid, settinggroupid, title, varname, value, description, optioncode, displayorder) 
VALUES (NULL, 2, 'News',' \$news', '', 'Insert forum news here...', 'textarea',' 7')";
@mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
You should have the string in double quotes and then you don't have to escape any of the single quotes. The only thing you need to escape is the dollar sign.

Mac