whats wrong with this peice of php code?
11-14-2005, 11:04 AM
|
whats wrong with this peice of php code?
|
Posts: 535
|
<?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..
|
|
|
|
11-14-2005, 11:28 AM
|
|
Posts: 880
Location: Leeds UK
|
try wrapping your $_POST[''] vars like so '{$_POST['']}'
Ibbo
|
|
|
|
11-14-2005, 02:20 PM
|
|
Posts: 535
|
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..
|
|
|
|
11-14-2005, 02:41 PM
|
|
Posts: 1,832
Location: Somewhere else entirely
|
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)
|
|
|
|
11-14-2005, 02:46 PM
|
|
Posts: 535
|
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.
|
|
|
|
11-14-2005, 04:03 PM
|
|
Posts: 1,832
Location: Somewhere else entirely
|
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..
|
|
|
|
11-14-2005, 06:21 PM
|
|
Posts: 535
|
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.
|
|
|
|
11-14-2005, 08:05 PM
|
|
Posts: 535
|
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..
|
|
|
|
11-15-2005, 03:41 AM
|
|
Posts: 1,832
Location: Somewhere else entirely
|
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)
|
|
|
|
|
« Reply to whats wrong with this peice of php code?
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|