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
NotOnUrNelly
Forum Commoner
Posts: 61 Joined: Wed Mar 24, 2004 4:45 pm
Post
by NotOnUrNelly » Fri Jul 21, 2006 3:33 am
Pimptastic | Please use 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 belowCode: Select all
$sql_quest = 'UPDATE `tblChart` SET `Score` = '.$avg.' WHERE `Question` ='.$QuestCR.'';
The values of the variables are
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
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.
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Fri Jul 21, 2006 3:37 am
Please try not to be lazy and format your post correctly. You have been told before!
Thanks
NotOnUrNelly
Forum Commoner
Posts: 61 Joined: Wed Mar 24, 2004 4:45 pm
Post
by NotOnUrNelly » Fri Jul 21, 2006 3:39 am
Sorry Im just trying to ammend it
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Fri Jul 21, 2006 3:40 am
NotOnUrNelly wrote: Sorry Im just trying to ammend it
Ive already done it!
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Fri Jul 21, 2006 3:42 am
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 » Fri Jul 21, 2006 3:55 am
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
did not look formatted correctly.
Thanks
NotOnUrNelly
Forum Commoner
Posts: 61 Joined: Wed Mar 24, 2004 4:45 pm
Post
by NotOnUrNelly » Fri Jul 21, 2006 4:05 am
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
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Fri Jul 21, 2006 4:10 am
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 » Fri Jul 21, 2006 4:12 am
Yeah, as you can see I'm still getting used to qoutes myself.
Thanks Again