parsing error ')' unexpected
06-03-2008, 04:30 PM
|
parsing error ')' unexpected
|
Posts: 76
|
Hello. I have this error.
Code:
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/russia5/public_html/month_conversion.php on line 9
Code:
<?php
//DB CONNECTION GOES HERE
$lookup = array("January" => '01', "February" => '02', "March" => '03', "April" => '04', "May" => '05', "June" => '06', "July" => '07', "August" => '08', "September" => '09', "October" => '10', "November" => '11', "December" => '12');
// use month names on your form
$month = $_POST["age_mth"]; // the name
$monthnum = $lookup[$month]; // the number
$query = "INSERT INTO subdomain_submission (age_month) VALUES ('.$monthnum.');"
print "month = $month";
print "monthnum = $monthnum";
?>
LINE 10 IS WHERE $lookup is at. So line 9 is blank.
Thanks to all who consider my problem
|
|
|
|
06-03-2008, 04:43 PM
|
Re: parsing error ')' unexpected
|
Posts: 1,228
|
Change:
PHP Code:
$query = "INSERT INTO subdomain_submission (age_month) VALUES ('.$monthnum.');"
To:
PHP Code:
$query = "INSERT INTO subdomain_submission (age_month) VALUES ('.$monthnum.')";
|
|
|
|
06-03-2008, 04:59 PM
|
Re: parsing error ')' unexpected
|
Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
The only error I can see like that is:
PHP Code:
$query = "INSERT INTO subdomain_submission (age_month) VALUES ('.$monthnum.');"
where you mix the PHP string " delimiter with the SQL one (')
The query should be written:
PHP Code:
$query = "INSERT INTO subdomain_submission (age_month) VALUES ('$monthnum');"
if the age_month column is a text or varchar field, or
PHP Code:
$query = "INSERT INTO subdomain_submission (age_month) VALUES ($monthnum);"
if age_month is a numeric field (integer)
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
06-03-2008, 05:28 PM
|
Re: parsing error ')' unexpected
|
Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
|
so given ->
LINE 10 IS WHERE $lookup is at. So line 9 is blank.
What's the code that should be where this -> //DB CONNECTION GOES HERE <- is ?
because that's where the error will be (you are probably missing a ")" on the line before the stated error line. (the code you haven't shown us)
__________________
Chris. ->> Please login or register to view this content. Registration is FREE <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
|
|
|
|
06-03-2008, 05:42 PM
|
Re: parsing error ')' unexpected
|
Posts: 1
Name: Ahsan
|
Hi,
Please add one additional semicolon after the query line. that is replace your :
$query = "INSERT INTO subdomain_submission (age_month) VALUES ('.$monthnum.');"
with the following correct line :
$query = "INSERT INTO subdomain_submission (age_month) VALUES ('.$monthnum.');";
then everything will be fine. Be a bit careful while from making these little mistakes pls.
Best Regards
Ahsan
|
|
|
|
06-03-2008, 06:35 PM
|
Re: parsing error ')' unexpected
|
Posts: 76
|
Thanks for the help everyone! I am getting it, but not quite. I am still getting 0 in the age_month field Here is what month_conversion.php is now outputting.
so the lookup table is not quite right, I believe
|
|
|
|
06-04-2008, 12:49 AM
|
Re: parsing error ')' unexpected
|
Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
|
Can you please give us the full PHP code? Also now that you're asking for help with your mysql please give us the table structure of your database too.
__________________
PHP Code:
<?php echo "Hello World"; ?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
|
|
|
|
06-05-2008, 09:59 PM
|
Re: parsing error ')' unexpected
|
Posts: 76
|
Okay... I will give you everything that I have, since I have spent an very long time on this and can not get it with many variants. I am doing something wrong. Thanks...
Question: Do I have a declaration problem with $month or $monthnum It is used in the form below.
First, here is the MySQL table structure for the fields we are dealing with.
Code:
age_day int(2) No 0
age_mth varchar(9) No
age_yr int(4) No 0
age_month char(2) No 0
Indexes: Keyname Type Cardinality Action Field
PRIMARY PRIMARY 21 sid
Create an index on columns
Next, here is the full coding on the loader or PHP page.
Code:
<?php
require_once("../includes/ru_config.php");
require_once("../includes/ru_connection.php");
require_once("../includes/ru_utils.php");
require_once("../includes/ru_data.php");
require_once("../libs/ru_smarty.php");
RU_CheckInject();
$lookup = array("January" => '01', "February" => '02', "March" => '03', "April" => '04', "May" => '05', "June" => '06', "July" => '07', "August" => '08', "September" => '09', "October" => '10', "November" => '11', "December" => '12');
// use month names on your form
WHERE IS $month or $monthnum declared? How do I do this?
$month = ($_POST[$profile['age_mth']]); // the name
$monthnum = $lookup[$month]; // the number
$query = "INSERT INTO `subdomain_submission` (age_month) VALUES ('{$monthnum}');";
print "month = $month";
print "monthnum = $monthnum";
?>
On logging into the above php page, I am getting
month = monthnum =
Question: Do I have a declaration problem with $month or $monthnum It is used in the form below.
$month should
Next, here is the form template
Code:
<html ">
</head>
<body>
<form action="?step={ $step+1 }" method="post" enctype="multipart/form-data" name="form2" { if $step < 3 } onSubmit="return isValid(this)" {/if} >
<input type="hidden" name="id" value="{$id}">
<TABLE >
{if $step eq 1}
'1 : ;
{else}
{$step}.' : Submit Your Photo #'.{$step-1};
{/if}
</STRONG></FONT></TD>
</TR>
{ if $step eq 1 }
<TD>
<select name="age" id="age" size="1">
<option value="0" selected>-- Select --</option>
<option value="16" {php} if (!empty($profile) and $profile['age'] == '20') echo ' selected' {/php}>16 yo</option>
<option value="17" {php} if (!empty($profile) and $profile['age'] == '21') echo ' selected' {/php}>17 yo</option>
<option value="18" {php} if (!empty($profile) and $profile['age'] == '23') echo ' selected' {/php}>18 yo</option>
<option value="19" {php} if (!empty($profile) and $profile['age']
</select>
</TD>
</TR>
<TR>
<TD align=right><strong></strong></TD>
<TD>
<select name="age_day" id="age_day" size="1">
<option value="0" selected>-- Select --</option>
<option value="01" {php} if (!empty($profile) and $profile['age_day'] == '01') echo ' selected' {/php}>01</option>
<option value="02" {php} if (!empty($profile) and $profile['age_day'] == '02') echo ' selected' {/php}>02</option>
<option value="03" {php} if (!empty($profile) and $profile['age_day'] == '03') echo ' selected' {/php}>03</option>
<option value="04"
</select>
</TD>
</TR>
<TR>
<TD align=right><strong></strong></TD>
<TD>
<select name="age_mth" id="age_mth" size="1">
<option value="0" selected>-- Select --</option>
<option value="January" {php} if (!empty($profile) and $profile['age_mth'] == 'January') echo ' selected' {/php}>January</option>
<option value="Feburary" {php} if (!empty($profile) and $profile['age_mth'] == 'Feburary') echo ' selected' {/php}>Feburary</option>
<option value="March" {php} if (!empty($profile) and $profile['age_mth'] == 'March') echo ' selected' {/php}>March</option>
<option value="April" {php} if (!empty($profile) and $profile['age_mth'] == 'April') echo ' selected' {/php}>April</option>
<option value="May" {php} if (!empty($profile) and $profile['age_mth'] == 'May')
</select>
</TD>
</TR>
<TR>
<TD align=right><strong>Ãîä ðîæäåíèÿ</strong></TD>
<TD>
<select name="age_yr" id="age_yr" size="1">
<option value="0" selected>-- Select --</option>
<option value="1993" {php} if (!empty($profile) and $profile['age_yr'] == '1993') echo ' selected' {/php}>1993</option>
<option value="1992" {php} if (!empty($profile) and $profile['age_yr'] == '1992') echo ' selected' {/php}>1992</option>
<option value="1991" {php} if (!empty($profile) and $profile['age_yr'] == '1991') echo ' selected' {/php}>1991</option>
<option value="1990"
</select>
</TD>
</body>
</html>
Next, here is the form php file.
Code:
<?php
require_once("includes/ru_config.php");
require_once("includes/ru_connection.php");
require_once("includes/ru_data.php");
require_once("includes/ru_utils.php");
require_once("libs/ru_smarty.php");
//RU_CheckInject();
//print "<pre>";
//print_r($_REQUEST);
if (empty($_REQUEST['step'])) $step = 1; else $step = $_REQUEST['step'];
if (empty($_REQUEST['id'])) $id = 0; else $id = $_REQUEST['id'];
function check_received_params($allowedParams_in, $arrayToCheck_in)
{
// makes sure only the items in the $allowedParams_in
// are found in the array $arrayToCheck_in
// returns true if there are no unexpected params in the array
// returns false otherwise
$numAllowed = count($allowedParams_in);
if (count($arrayToCheck_in) <= $numAllowed) {
while (list($k, $v) = each($arrayToCheck_in)) {
$found = false;
for($i = 0; $i < $numAllowed; $i++) {
if ($k == $allowedParams_in[$i]) {
$found = true;
break;
}
}
if (!$found) {
return false;
}
}
} else {
return false;
}
return true;
}
if (!empty($_POST))
{
if ($step < 3) // insert/update info
{
$fields = $values = array();
unset($_POST['Submit']);
if (empty($_POST['id']))
{
unset($_POST['id']);
foreach ($_POST as $field=>$value)
{
$fields[] = $field;
mysql_query($query);
$id = mysql_insert_id();
}
$qryString = array();
$currentID = $_POST['id'];
unset($_POST['id']);
foreach ($_POST as $field=>$value)
{
$qryString[] = $field.' = "'.htmlspecialchars(trim($value)).'" ';
}
$query = 'UPDATE subdomain_submission SET '.implode(',', $qryString).' WHERE sid = "'.$currentID.'"';
mysql_query($query);
}
}
mysql_query($query);
}
}
elseif (!empty($_COOKIE['authcode']))
{
//echo "COOKIE :: " . $_COOKIE['authcode'];
$query = 'SELECT * FROM subdomain_submission WHERE sid = "'.$_COOKIE['authcode'].'"';
$result = mysql_query($query);
if (mysql_num_rows($result))
{
$profile = mysql_fetch_assoc($result);
$id = $_COOKIE['authcode'];
}
}
$smarty->display("forms/submission-russian_subdomain.tpl");
?>
|
|
|
|
06-05-2008, 11:27 PM
|
Re: parsing error ')' unexpected
|
Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
|
From a quick view change this
PHP Code:
WHERE IS $month or $monthnum declared? How do I do this?
$month = ($_POST[$profile['age_mth']]); // the name
To
PHP Code:
$month = ($_POST['age_mth']);
See if that makes any difference.
__________________
PHP Code:
<?php echo "Hello World"; ?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
|
|
|
|
06-06-2008, 11:22 AM
|
Re: parsing error ')' unexpected
|
Posts: 76
|
I tried it before and I just tried it again. I am still getting the same out put from the script month = monthnum =
It does not see the results from the submitted variable $_POST['age_mth'] or $_POST[$profile['age_mth']] it sayst this is empty. I have tried every combination I can think of. thanks again.
So, you do not see a problem with the declaring of the varibles $month or $monthnum
Last edited by russia5; 06-06-2008 at 11:25 AM..
|
|
|
|
06-06-2008, 05:30 PM
|
Re: parsing error ')' unexpected
|
Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
|
Try putting this at the top of the page and see what it says.
PHP Code:
foreach($_POST as $key => $value){ echo "<p>Key: ".$key." Value: ".$value."</p>";}
__________________
PHP Code:
<?php echo "Hello World"; ?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
|
|
|
|
06-07-2008, 12:22 PM
|
Re: parsing error ')' unexpected
|
Posts: 76
|
I put it at the top, in the middle and at the end. I took out print and left it in. The result was, I got nothing echo'd. white space.
|
|
|
|
06-07-2008, 01:22 PM
|
Re: parsing error ')' unexpected
|
Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
|
If the foreach I said echo'd nothing then $_POST is empty. Do you have a working example of this that I could look at?
__________________
PHP Code:
<?php echo "Hello World"; ?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
|
|
|
|
06-07-2008, 02:10 PM
|
Re: parsing error ')' unexpected
|
Posts: 76
|
The form successfully posts the narrative month. That is, it puts octomer in the MySQL field, age_mth The form loader php file, I have listed above, shows the variable to upload the narrative, $profile[age_mth]
The test site that we are using to build this is www.russiansweets.us the form can be found at the bottom of the page under "sign up" this is only a site we are using to test and develop, however it does work.
|
|
|
|
06-07-2008, 04:43 PM
|
Re: parsing error ')' unexpected
|
Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
|
It'd seem, age_mth=0 is the default so $_POST['age_mth'] should be numerical. But it still doesn't explain why the foreach I posted above is showing as empty, if it's not outputting anything then nothing is being posted by the form.
__________________
PHP Code:
<?php echo "Hello World"; ?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
|
|
|
|
06-07-2008, 06:29 PM
|
Re: parsing error ')' unexpected
|
Posts: 76
|
Would I need to change the array to 01 => january?
|
|
|
|
06-07-2008, 07:42 PM
|
Re: parsing error ')' unexpected
|
Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
|
First off, does $_POST contain anything at all? It won't matter what you change until $_POST contains data.
__________________
PHP Code:
<?php echo "Hello World"; ?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
|
|
|
|
06-08-2008, 11:25 AM
|
Re: parsing error ')' unexpected
|
Posts: 76
|
The form successfully posts to MySQL, so the supervariables would have to hold something. From the form above, you can see we have $_REQUEST and $_POST The form handling script has anti hack coding within it which may be the $_POST. (I just happen to think about that) could it be possible the variables are in the $_REQUEST
|
|
|
|
06-08-2008, 02:07 PM
|
Re: parsing error ')' unexpected
|
Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
|
$_REQUEST contains $_COOKIE, $_POST, and $_GET and I believe in that order. The danger with it is if you have $id = $_REQUEST['id'] and expect id to be in a cookie or to be POSTed and I use ?id=1 it'll use that instead. So don't use $_REQUEST, use $_POST there instead (that may be the problem actually)
__________________
PHP Code:
<?php echo "Hello World"; ?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
|
|
|
|
06-10-2008, 01:37 PM
|
Re: parsing error ')' unexpected
|
Posts: 76
|
I exchanged REQUEST for POST, and I still got month = monthnum = as an output of /month_conversion.php Plus, the images would not load. I have looked at this forever and I am still stumped.
|
|
|
|
|
« Reply to parsing error ')' unexpected
|
|
|
| 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
|
|
|
|