Structuring SQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NotOnUrNelly
Forum Commoner
Posts: 61
Joined: Wed Mar 24, 2004 4:45 pm

Structuring SQL

Post 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]
Last edited by NotOnUrNelly on Fri Jul 21, 2006 3:38 am, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Please try not to be lazy and format your post correctly. You have been told before! :twisted:

Thanks
NotOnUrNelly
Forum Commoner
Posts: 61
Joined: Wed Mar 24, 2004 4:45 pm

Post by NotOnUrNelly »

Sorry Im just trying to ammend it
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

NotOnUrNelly wrote:Sorry Im just trying to ammend it
Ive already done it!
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Soemthing like this

Code: Select all

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

$sql_quest = 'UPDATE `tblChart` SET `Score` = ''.$avg.'' WHERE `Question` = ''.$QuestCR.'';
NotOnUrNelly
Forum Commoner
Posts: 61
Joined: Wed Mar 24, 2004 4:45 pm

Post 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
NotOnUrNelly
Forum Commoner
Posts: 61
Joined: Wed Mar 24, 2004 4:45 pm

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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)
NotOnUrNelly
Forum Commoner
Posts: 61
Joined: Wed Mar 24, 2004 4:45 pm

Post by NotOnUrNelly »

Yeah, as you can see I'm still getting used to qoutes myself.

Thanks Again
Post Reply