473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Parse error with php/java script

Hello
I have found the following script php/java for dynamic menu lists. Where a
selection from the first updates (filters items in) the other. I have
modified it for my tables.
However I am getting an error

Parse error: parse error, unexpected T_VAR in
e:\domains\i\iddsoftware.co.uk\user\htdocs\Questio nDB\Questions.php on line
42

line 42 being
var mainselect = document.FormName.MainCategory;

Im fairly new to php and dont use Java upto now. Can anyone see where I ve
gone wrong

<?php
session_start();
include("../include/connection.php");
include("../Secure/login.php");
$Heading= 'QUESTION SELECTOR';
$Menu='<a href="../Secure/logout.php">Logout</a><br>';
include 'HeadQuest.php';
$Query = "SELECT SubjectNo, SubjectDesc, StatusID FROM Subjects WHERE
StatusID = 1 ORDER BY SubjectDesc ASC";
$Result = mysql_query( $Query, $conn );

?>

<HTML>
<HEAD>
<SCRIPT language="JavaScript">

function BodyLoad()
{

var select = document.FormName.MainCategory;

select.options[0] = new Option("Choose One");
select.options[0].value = 0;

<?PHP

$ctr = 1;
While( $Row = mysql_fetch_array($Result) ) {
echo "select.options[".$ctr."] = new
Option(\"".$Row['SubjectNo']."\");\n";
echo "select.options[".$ctr."].value = \"".$Row['SubjectNo']."\";\n";
$ctr++;
}
?>
}

function Fill_Sub()
{

<?PHP
var mainselect = document.FormName.MainCategory;
var subselect = document.FormName.SubCategory;

if( mainselect.options[mainselect.selectedIndex].value != 0 ) {

subselect.length = 0;
}

$Query = "SELECT SubjectNo, SubjectDesc, StatusID FROM Subjects WHERE
StatusID = 1 ORDER BY SubjectDesc ASC";
$Result = mysql_query($Query, $conn );

while( $Row = mysql_fetch_array($Result) ) {
?>
if( mainselect.options[mainselect.selectedIndex].text == "<?PHP echo
$Row['SubjectNo']; ?>" ) {
<?PHP

$Query2 = "SELECT TopicID, TopicDesc, KS, SubjectNo FROM ttopic WHERE
StatusID = 1 AND SubjectNo = ".$row['SubjectNo']." ORDER BY TopicDesc ASC";
$Result2 = mysql_query($Query2, $conn );

$ctr = 0;

While( $Row2 = mysql_fetch_array($Result2) ) {
echo "subselect.options[".$ctr."] = new
Option(\"".$Row2['TopicID']."\");\n";
echo "subselect.options[".$ctr."].value =
\"".$Row2['TopicID']."\";\n";
$ctr++;
}
?>
}
}

<?PHP
}

mysql_close($conn);
?>
}

</SCRIPT>
</HEAD>

<BODY onload="BodyLoad();">
<FORM name="FormName" method="POST" action="">
<TABLE border="1">
<TR>
<TD>Main Category</TD>
<TD>Sub Category</TD>
</TR>
<TR>
<TD>
<SELECT name="MainCategory" onchange="Fill_Sub();">
</SELECT>
</TD>

<TD>
<SELECT name="SubCategory" size="4">
</SELECT>
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
Nov 23 '05 #1
6 4062
Ian Davies wrote:

Parse error: parse error, unexpected T_VAR in
e:\domains\i\iddsoftware.co.uk\user\htdocs\Questio nDB\Questions.php on line
42
<snip>
function Fill_Sub()
{

<?PHP
This is in the wrong spot...
var mainselect = document.FormName.MainCategory;
var subselect = document.FormName.SubCategory;

if( mainselect.options[mainselect.selectedIndex].value != 0 ) {

subselect.length = 0;
}
This is where the "<?php" should be...
$Query = "SELECT SubjectNo, SubjectDesc, StatusID FROM Subjects WHERE
StatusID = 1 ORDER BY SubjectDesc ASC";
$Result = mysql_query($Query, $conn );


<snip>

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Nov 23 '05 #2
Thanks
That helped
But now get a syntax error on line 69
which is

echo "subselect.options[".$ctr."].value =
\"".$Row2['TopicID']."\";\n";

my debugger is saying

if( mainselect.options[mainselect.selectedIndex].value == "12" ) {
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in e:\domains\i\mysite\user\htdocs\myfolder\Questions .php on line
67
} }

It would seem that there is a problem with

mainselect.options[mainselect.selectedIndex].value

Ian

"Justin Koivisto" <ju****@koivi.com> wrote in message
news:uP********************@onvoy.com...
Ian Davies wrote:

Parse error: parse error, unexpected T_VAR in
e:\domains\i\iddsoftware.co.uk\user\htdocs\Questio nDB\Questions.php on line 42

<snip>
function Fill_Sub()
{

<?PHP


This is in the wrong spot...
var mainselect = document.FormName.MainCategory;
var subselect = document.FormName.SubCategory;

if( mainselect.options[mainselect.selectedIndex].value != 0 ) {

subselect.length = 0;
}


This is where the "<?php" should be...
$Query = "SELECT SubjectNo, SubjectDesc, StatusID FROM Subjects WHERE StatusID = 1 ORDER BY SubjectDesc ASC";
$Result = mysql_query($Query, $conn );


<snip>

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com

Nov 23 '05 #3
Ian Davies wrote:
Thanks
That helped
But now get a syntax error on line 69
which is

echo "subselect.options[".$ctr."].value =
\"".$Row2['TopicID']."\";\n";

my debugger is saying

if( mainselect.options[mainselect.selectedIndex].value == "12" ) {
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in e:\domains\i\mysite\user\htdocs\myfolder\Questions .php on line
67
} }

It would seem that there is a problem with

mainselect.options[mainselect.selectedIndex].value


Or there's something wrong with the query. You blindly start a while
loop without first checking to see if the query has succeeded. In this
case, if $Result isn't a valid result resource, the query failed for
some reason... to help debug, use mysql_error() to see what the problem is.

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Nov 23 '05 #4
Ian Davies wrote:
Hello
I have found the following script php/java for dynamic menu lists. Where a
selection from the first updates (filters items in) the other. I have
modified it for my tables.
However I am getting an error
When posting code, post what is received at the client (use view
source). The PHP side should be discussed in a PHP forum.

Once you have sorted out what the client should get, then you can work
out how to generate it.

Parse error: parse error, unexpected T_VAR in
e:\domains\i\iddsoftware.co.uk\user\htdocs\Questio nDB\Questions.php on line
42

line 42 being
var mainselect = document.FormName.MainCategory;

Im fairly new to php and dont use Java upto now. Can anyone see where I ve
gone wrong
Asking PHP questions in a JavaScript group? Thinking JavaScript is
Java? ;-)

<?php
session_start();
include("../include/connection.php");
include("../Secure/login.php");
$Heading= 'QUESTION SELECTOR';
$Menu='<a href="../Secure/logout.php">Logout</a><br>';
include 'HeadQuest.php';
$Query = "SELECT SubjectNo, SubjectDesc, StatusID FROM Subjects WHERE
StatusID = 1 ORDER BY SubjectDesc ASC";
$Result = mysql_query( $Query, $conn );

?>

<HTML>
<HEAD>
<SCRIPT language="JavaScript">
The language attribute is deprecated, type is required:

<script type="text/javascript">


function BodyLoad()
{

var select = document.FormName.MainCategory;

select.options[0] = new Option("Choose One");
select.options[0].value = 0;
IE has issues with setting option attributes this way. Set all the
values in one go (hey, saves a line of code too):

select.options[0] = new Option("Choose One", "0", true, true);
sets the first option to have text 'Choose One', value as '0', default
selected as true and currently selected as true.


<?PHP

$ctr = 1;
While( $Row = mysql_fetch_array($Result) ) {
echo "select.options[".$ctr."] = new
Option(\"".$Row['SubjectNo']."\");\n";
echo "select.options[".$ctr."].value = \"".$Row['SubjectNo']."\";\n";
$ctr++;
}
?>
}

function Fill_Sub()
{

<?PHP
var mainselect = document.FormName.MainCategory;
var subselect = document.FormName.SubCategory;

if( mainselect.options[mainselect.selectedIndex].value != 0 ) {
The value of a form control is always returned as a string, so be
careful when evaluating it. In this case it is OK because the string
'0' and number 0 will be evaluated as you expect, but sometimes it will
trip you up.


subselect.length = 0;
} [...] <TD>
<SELECT name="SubCategory" size="4">
</SELECT>
</TD>


A select element with no options is invalid HTML.

[...]
--
Rob
Nov 23 '05 #5
RobG wrote:
When posting code, post what is received at the client (use view
source). The PHP side should be discussed in a PHP forum.
It was - 4 of them.
Asking PHP questions in a JavaScript group? Thinking JavaScript is
Java? ;-)


More like someone not sure if it was a php or js thing. The post went to
4 php groups, and one js group...

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Nov 23 '05 #6
Hello

The script here is modified from a previous script where I have not
atempted to use java to update a second dropdownmenu/listbox (havent decided
which to use yet) from the item selected in the first. In the previous
script I use the exact same sqls which work fine.
Go here to see these SQLs working in the dropdown lists
http://www.iddsoftware.co.uk/Questio...ionsBrowse.php

Ian
"Justin Koivisto" <ju****@koivi.com> wrote in message
news:Xe******************************@onvoy.com...
Ian Davies wrote:
Thanks
That helped
But now get a syntax error on line 69
which is

echo "subselect.options[".$ctr."].value =
\"".$Row2['TopicID']."\";\n";

my debugger is saying

if( mainselect.options[mainselect.selectedIndex].value == "12" ) {
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in e:\domains\i\mysite\user\htdocs\myfolder\Questions .php on line 67
} }

It would seem that there is a problem with

mainselect.options[mainselect.selectedIndex].value
Or there's something wrong with the query. You blindly start a while
loop without first checking to see if the query has succeeded. In this
case, if $Result isn't a valid result resource, the query failed for
some reason... to help debug, use mysql_error() to see what the problem

is.
--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com

Nov 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ehartwig | last post by:
I recently created a script for user verification, solved my emailing issues, and then re-created the script in order to work well with the new PHP 5 that I installed on my server. After...
6
by: Ian Davies | last post by:
Hello I have found the following script php/java for dynamic menu lists. Where a selection from the first updates (filters items in) the other. I have modified it for my tables. However I am...
5
by: js | last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss". I need to parse the text using System.DateTime.Parse() function with custom format. I got an error using the following code. ...
0
by: urmyfriend | last post by:
Hi, I am getting the parse error while i try to execute a simple sql query in postgres. java.sql.SQLException: ERROR: parser: parse error at or near "and" at character 58 The Query has...
2
by: urmyfriend | last post by:
Hi, I am getting the parse error while i try to execute a simple sql query in postgres. java.sql.SQLException: ERROR: parser: parse error at or near "and" at character 58 The Query has...
14
by: dbldeegd | last post by:
My Java Script executes fine on an test HTML page, but on the required page which is php results in an error. the page The script drops in message box when the page is loaded since the script...
12
by: Inny | last post by:
Im trying to rewrite a link with a href function. I need to parse a query string within it ('+tid') But all attempts Have falied. The current onclick/ link function <a href="java...
13
by: Gilles Ganault | last post by:
Hello Is there a tool on Linux/FreeBSD that can parse a PHP script to make sure there's no compile-time issues? I just noticed that I copy/pasted some code that had lines longer that can fit...
9
akohistani
by: akohistani | last post by:
I am having Parse error problem with my newly purchased Php upload script I have uploaded the script and I get the error below Parse error: syntax error, unexpected $end in URL/functions.php on...
7
by: adrian.bartholomew | last post by:
Im getting an error: Error: unterminated string literal Source File: http://98.214.38.110/allfours/site_flash/2.php Line: 75, Column: 37 Source Code: if (_ie == true) document.writeln(' ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.