Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
whats wrong with this peice of php code?
Old 11-14-2005, 11:04 AM whats wrong with this peice of php code?
Village Idiot's Avatar
Webmaster Talker

Posts: 535
Trades: 0
<?php
$dbhost = 'host';
$dbname = 'db';
$dbuser = 'dbu';
$dbpasswd = 'pass';

mysql_connect($dbhost,$dbuser,$dbpasswd) or die("cant connect");
mysql_selectdb($dbname) or die("cant select db");

//set the last (at this point, the current active one) as an archive
mysql_query("UPDATE poll_options SET active = 1 WHERE active = 2");

//get the poll archive number
$result = mysql_query("SELECT * FROM poll_options WHERE active = 2");
$pollnum = mysql_result($result,'0','pollnum');
$newpollnum = $pollnum +1;
//now insert the new poll data for the new poll
$query = "INSERT INTO poll_options VALUES($newpollnum,$_POST['question']
,$_POST['numofqs'],2,$_POST['question1'],$_POST['question2']
,$_POST['question3'],$_POST['question4'],$_POST['question5'],$_POST['question6'],
$_POST['question7'],$_POST['question8'],$_POST['question9'],$_POST['question10'],
0,0,0,0,0,0,0,0,0,0)";
mysql_query($query);



?>

I get
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/7/d92632777/htdocs/wsc92632785/nrc/newpoll.php on line 18


line 18 being the bolded line
__________________
I have the heart of a child, I keep it in a jar on my desk.

Last edited by Village Idiot; 11-14-2005 at 02:37 PM..
Village Idiot is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-14-2005, 11:28 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
try wrapping your $_POST[''] vars like so '{$_POST['']}'

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 11-14-2005, 02:20 PM
Village Idiot's Avatar
Webmaster Talker

Posts: 535
Trades: 0
im assuming without the single quotes around {$_POST['']}

edit: ok, I did that, I not get the same error on line 19.

$query = "INSERT INTO poll_options VALUES($newpollnum,{$_POST['question']}
,{$_POST['numofqs']},{2,$_POST['question1']},{$_POST['question2']}
,{$_POST['question3']},{$_POST['question4']},{$_POST['question5']},{$_POST['question6']},
{_POST['question7']},{$_POST['question8']},{$_POST['question9']},{$_POST['question10']},
0,0,0,0,0,0,0,0,0,0)";

the bolded line being the error line
__________________
I have the heart of a child, I keep it in a jar on my desk.

Last edited by Village Idiot; 11-14-2005 at 02:31 PM..
Village Idiot is offline
Reply With Quote
View Public Profile
 
Old 11-14-2005, 02:41 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
You have a random 2, in that line:
,{$_POST['numofqs']},{2,$_POST['question1']},{$_POST['question2']}

If you want an actual 2 for a mySQL value, put the 2 outside the {} as an item on it's own. If not then delete it.

Are all these $_POST variables numbers? If any of them are strings you will need quotes just outside the {} so that those quotes get sent to mySQL as part of the string.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 11-14-2005, 02:46 PM
Village Idiot's Avatar
Webmaster Talker

Posts: 535
Trades: 0
that was a misplaced braket.

and the posts are all strings, the sql database is useing a text variable to store them if that makes a difference

edit: no more errors, but it is still acting weird
__________________
I have the heart of a child, I keep it in a jar on my desk.
Village Idiot is offline
Reply With Quote
View Public Profile
 
Old 11-14-2005, 04:03 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
If they are strings I'd code it by separating the variables from the string:

PHP Code:
$query "INSERT INTO poll_options VALUES($newpollnum,'" $_POST['question'] . "',"
$_POST['numofqs'] . ", 2, '"
$_POST['question1'] . "','"
$_POST['question2'] . "','"
$_POST['question3'] . "','"
$_POST['question4'] . "','"
$_POST['question5'] . "','"
$_POST['question6'] . "','"
$_POST['question7'] . "','"
$_POST['question8'] . "','"
$_POST['question9'] . "','"
$_POST['question10']
"',0,0,0,0,0,0,0,0,0,0)"
I'm assuming that $newpollnum and $_POST['numofqs'] are numbers and so don't need quotes. (Although numbers still work with quotes - strings won't work without them tho)
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)

Last edited by 0beron; 11-14-2005 at 04:09 PM..
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 11-14-2005, 06:21 PM
Village Idiot's Avatar
Webmaster Talker

Posts: 535
Trades: 0
I got that done, the rest of the error shouldnt be to hard. thanks for your help.
__________________
I have the heart of a child, I keep it in a jar on my desk.
Village Idiot is offline
Reply With Quote
View Public Profile
 
Old 11-14-2005, 08:05 PM
Village Idiot's Avatar
Webmaster Talker

Posts: 535
Trades: 0
ok, the query wll run but none of the post variables will go in

Code:
$query = "INSERT INTO poll_options VALUES('$newpollnum','{$_POST[question]}'
,'{$_POST[numofqs]}','2','{$_POST[question1]}','{$_POST[question2]}'
,'{$_POST[question3]}','{$_POST[question4]}','{$_POST[question5]}','{$_POST[question6]}',
'{$_POST[question7]}','{$_POST[question8]}','{$_POST[question9]}','{$_POST[question10]}',
'0','0','0','0','0','0','0','0','0','0')";
__________________
I have the heart of a child, I keep it in a jar on my desk.

Last edited by Village Idiot; 11-14-2005 at 09:14 PM..
Village Idiot is offline
Reply With Quote
View Public Profile
 
Old 11-15-2005, 03:41 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Check that they are actually set to what you think they are by echoing some of them to the screen. They may be empty because of a bug further upstream.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Reply     « Reply to whats wrong with this peice of php code?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 4.73468 seconds with 12 queries