Page 1 of 1

Structuring SQL

Posted: Fri Jul 21, 2006 3:33 am
by NotOnUrNelly
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi all,

Im having a bit of a problem structuring an sql update query.

the code I am trying to use is listed below

Code: Select all

$sql_quest = 'UPDATE `tblChart` SET `Score` = '.$avg.' WHERE `Question` ='.$QuestCR.'';
The values of the variables are

Code: Select all

$avg = 4.77;
$QuestCR = Q1;
the sql that is echoed to the page is

Code: Select all

UPDATE tblChart SET Score = '4.77' WHERE Question ='Q1'
Hope someone can help

Many Thanks
Jamie


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Jul 21, 2006 3:37 am
by JayBird
Please try not to be lazy and format your post correctly. You have been told before! :twisted:

Thanks

Posted: Fri Jul 21, 2006 3:39 am
by NotOnUrNelly
Sorry Im just trying to ammend it

Posted: Fri Jul 21, 2006 3:40 am
by JayBird
NotOnUrNelly wrote:Sorry Im just trying to ammend it
Ive already done it!

Posted: Fri Jul 21, 2006 3:42 am
by JayBird
Soemthing like this

Code: Select all

$avg = 4.77;
$QuestCR = "Q1";

$sql_quest = 'UPDATE `tblChart` SET `Score` = ''.$avg.'' WHERE `Question` = ''.$QuestCR.'';

Posted: Fri Jul 21, 2006 3:55 am
by NotOnUrNelly
Thanks for your reply that did not seem to work, heres what I entered

Code: Select all

$avg = 4.77; 
$QuestCR = "Q1"; 

$sql_quest = 'UPDATE `tblChart` SET `Score` = ''.$avg.'' WHERE `Question` = ''.$QuestCR.''; 
sql_return($sql_text);
echo $sql_quest;
This then gave me the following error message

Code: Select all

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/x04recru/public_html/client/process_survey.php on line 70
I'm working in dreamweaver and when I pasted your selected code into the page

the line

Code: Select all

sql_return($sql_text);
did not look formatted correctly.

Thanks

Posted: Fri Jul 21, 2006 4:05 am
by NotOnUrNelly
Hi,

I have managed to get this working by fiddling with the ' 's

The final code I used is

Code: Select all

$sql_quest = 'UPDATE `tblChart` SET `Score` = '.$avg.' WHERE `Question` = "'.$QuestCR.'"';
Thanks for putting me on the right lines

Jamie

Posted: Fri Jul 21, 2006 4:10 am
by JayBird
Oooops, my bad.

Should have been

Code: Select all

$sql_quest = 'UPDATE `tblChart` SET `Score` = '.$avg.' WHERE `Question` = ''.$QuestCR.''';
(missed a single quote off the end)

Posted: Fri Jul 21, 2006 4:12 am
by NotOnUrNelly
Yeah, as you can see I'm still getting used to qoutes myself.

Thanks Again