New Comer, with a Question.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Andy
Forum Newbie
Posts: 2
Joined: Thu Oct 17, 2002 8:18 pm

New Comer, with a Question.

Post 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.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

possible solution

Post 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 :?:
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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.
Andy
Forum Newbie
Posts: 2
Joined: Thu Oct 17, 2002 8:18 pm

Post 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 $.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply