473,507 Members | 6,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

parse error in nested query - please help.

I am having troubles finding the parse error in this script. I've been
checking for weeks. I am too new to the subject I guess.

I am trying to show a readord and them have a form at the bottom of the
page for inputting data to Update the record. I get a parse error that
points to the last line in the script so I know it is something I am missing
earlier in the script but doing a line by line it seems fine to me.

Thanks for any atempt and suggestions.

Polar :)

------------------------------
<--cut--
$query = "SELECT sub_id, username, story_title, DATE_FORMAT(date_submitted,
'%m/%d/%y'), category, story FROM Submission WHERE date_processed < 1 LIMIT
0,1";

$result = @mysql_query ($query); // Run the query.
if ($result) { // If OK, display the record.
echo '<table align="center" cellspacing="5" cellpadding="1" border="0"
width="500"><span><tr><td align="left" width="100">Story ID:</td><td
align="left" width="100">Name</td><td align="left" width="250">Title</td><td
align="left" width="100">Date&nbsp;Submitted</td><td align="left"
width="50">Category</td></tr><tr><td colspan="5"></span><hr></td></tr>';

// Fetch and print the record.
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo"<tr><td align=\"left\" width=\"100\">"
..$row[0]
.."</td><td align=\"left\" width=\"100\">"
..$row[1]
.."</td> <td align=\"left\"width=\"250\">"
..$row[2]
.."</td><td align=\"left\" width=\"50\">"
..$row[3]
.."</td><td align=\"left\" width=\"50\">"
..$row[4]
.."</td></tr><tr><td colspan=\"5\"width=\"500\"><br>"
..nl2br($row[5])
.."</td></tr>\n";
}
echo '</table>';
echo '<hr>';

if (isset($_POST['submit'])) { // Handle the form.

if (isset($_POST['accepted']) == 'Y') {
$acc = $_POST['accepted'];
echo "<b><p>Great A story to pass on!</p></b>";
$query = "UPDATE Submission SET reader={$_SESSION['username']},
date_processed=NOW(), accepted=$acc WHERE sub_id=$row[0]";

} elseif (isset($_POST['accepted']) == 'N') {
$acc = $_POST['accepted'];
echo "<b><p>Try again with a new story!</p></b>";
$query = "UPDATE Submission SET reader={$_SESSION['username']},
date_processed=NOW(), accepted=$acc WHERE sub_id=$row[0]";
$result = @mysql_query ($query); // Run the query.
if (mysql_affected_rows() == 1) { // If it ran OK.
echo 'Done';
include ('includes/footer.html'); // Include the HTML footer.
exit();
} else { // If no accepted was selected...
$accepted = NULL;
echo '<p><b>You forgot to enter Yes or No for the story
acceptance!</b></p>';

}

}

?>
Jul 17 '05 #1
8 2180
Polar wrote:
I am having troubles finding the parse error in this script. I've been
checking for weeks. I am too new to the subject I guess.


Count the number of "{" and compare with the number of "}".

I imagine they'll be different :)

--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #2
Thanks Pedro

I went over that many times - thinking the same thing - and low any beold on
my second to last bunch of hair I found it

Now I have a new problem. The query is not updating the record.

the $_Session['username'] is available as it is posting on top of the screen
about the form.
the Now() is evident it should be ok as is Accepted that leaves the
qualifier of the sud_id?

....

if (isset($_POST['accepted']) == 'Y') {
$query = "UPDATE Submission SET reader={$_SESSION['username']},
date_processed=NOW(), accepted='Y' WHERE sub_id=$row[0]";
echo "<b><p>Great A story to pass on!</p></b>";

....

is there an error here in my syntax That I am not seeing?

Thanks for the time and any comments

Polar :)

Jul 17 '05 #3
I noticed that Message-ID: <8MkGc.30436$P7.21937@pd7tw3no> from Polar
contained the following:
if (isset($_POST['accepted']) == 'Y') {
$query = "UPDATE Submission SET reader={$_SESSION['username']},
date_processed=NOW(), accepted='Y' WHERE sub_id=$row[0]";
echo "<b><p>Great A story to pass on!</p></b>";

...

is there an error here in my syntax That I am not seeing?


Not sure you can use isset() like that
http://uk.php.net/manual/en/function.isset.php
And where is $row[0] coming from?

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #4
Polar wrote:
Now I have a new problem. The query is not updating the record.

the $_Session['username'] is available as it is posting on top of the screen
about the form.
the Now() is evident it should be ok as is Accepted that leaves the
qualifier of the sud_id?

...

if (isset($_POST['accepted']) == 'Y') {
$query = "UPDATE Submission SET reader={$_SESSION['username']},
date_processed=NOW(), accepted='Y' WHERE sub_id=$row[0]";
echo "<b><p>Great A story to pass on!</p></b>";

...

is there an error here in my syntax That I am not seeing?


Yes, in SQL syntax. I'll leave it up to you to find :)

You do not show your mysql_query() call and *most importantly* how
you're checking for errors!

I usually do (pseudo-code)

<?php
$query = "whatever";
$result = mysql_query($query)
or die('Error in query [' . $query . ']. The error was: ' . mysql_error());
?>

Hint: is $_SESSION['username'] a string?

--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #5
Pedro Graca wrote:
I usually do (pseudo-code)

<?php
$query = "whatever";
$result = mysql_query($query)
or die('Error in query [' . $query . ']. The error was: ' . mysql_error());
?>

Hint: is $_SESSION['username'] a string?


Okay I'll hazard a guess on this one. I haven't tested this particular
solution, but I've occasionally run into similar problems.

If Polar's $query is holding a string, is it possible that the php
expressions must be concatenated as they are in Pedro's example? For
instance, wouldn't you really need to do something like this:

$query = "UPDATE Submission SET reader='".{$_SESSION['username']}."',
date_processed=NOW(), accepted='Y' WHERE sub_id='".$row[0]."'";

Also, wouldn't you want to do something like

/*temporary error check line*/
echo $query;

Just to make sure the query looks the way it's supposed to?

Hope this helps.

Jul 17 '05 #6
I posted the full script ( I hope ) at the very beginning of the thread.

Thanks for the info and not just giving me the answer - I have only been
doing this for about 3 weeks now. So ALL this is new.

thanks again I'll let you know how my crawling goes...

the weekender coder

Polar :)
"'bonehead" <se*********@here.org> wrote in message
news:40**************@here.org...
Pedro Graca wrote:
I usually do (pseudo-code)

<?php
$query = "whatever";
$result = mysql_query($query)
or die('Error in query [' . $query . ']. The error was: ' . mysql_error()); ?>

Hint: is $_SESSION['username'] a string?


Okay I'll hazard a guess on this one. I haven't tested this particular
solution, but I've occasionally run into similar problems.

If Polar's $query is holding a string, is it possible that the php
expressions must be concatenated as they are in Pedro's example? For
instance, wouldn't you really need to do something like this:

$query = "UPDATE Submission SET reader='".{$_SESSION['username']}."',
date_processed=NOW(), accepted='Y' WHERE sub_id='".$row[0]."'";

Also, wouldn't you want to do something like

/*temporary error check line*/
echo $query;

Just to make sure the query looks the way it's supposed to?

Hope this helps.

Jul 17 '05 #7
I noticed that Message-ID: <40**************@here.org> from 'bonehead
contained the following:
/*temporary error check line*/
echo $query;

Just to make sure the query looks the way it's supposed to?


I usually do that and then paste the result into phpmyadmin That
usually helps me find any SQL syntax errors.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #8
'bonehead wrote:
Pedro Graca wrote:
<?php
$query = "whatever";
$result = mysql_query($query)
or die('Error in query [' . $query . ']. The error was: ' . mysql_error());
?>
If Polar's $query is holding a string, is it possible that the php
expressions must be concatenated as they are in Pedro's example? For
instance, wouldn't you really need to do something like this:

$query = "UPDATE Submission SET reader='".{$_SESSION['username']}."',
date_processed=NOW(), accepted='Y' WHERE sub_id='".$row[0]."'";


No, not really. The string building of Polar's query is ok.
I don't like double quotes, but my die() expression could have been
written

die("Error in query [$query]. The error was: " . mysql_error());

Also, wouldn't you want to do something like

/*temporary error check line*/
echo $query;

Just to make sure the query looks the way it's supposed to?


That is also a good idea.
The idea behind the die is to get the query itself written to the output
as long as the reason for failure. Suppose you have this query

UPDATE xyz SET id=8 WHERE id=2

and try to run it on a database that has no xyz table. The die() output
will be something like

Error in query [UPDATE xyz SET id=8 WHERE id=2]. The error
was: Table 'xyz' doesn't exist
--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #9

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

Similar topics

3
2913
by: josh dismukes | last post by:
/// here is the code i'm getting a parse error on the last line of the code which /// is </html> any help will be much appreciated. <?php session_start ();
6
19010
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...
2
4558
by: Michael . | last post by:
I had an error before involving a temporary table, and that has been taken care of... The last message I wrote where it seemed to have needed it after I added it was because of different...
0
1024
by: jinapaia | last post by:
hi, i am getting a message Parse error:parse error, unexpected $...please help with this code: <?php require_once('db_login.php'); $sdbh = ""; $expire = 900; function sess_open($save_path,...
36
7946
by: rhys | last post by:
My Gurus and Angels -- Please pardon this old-school programmer, only recently enlightened to open-source, having been trapped in the convenience of proprietary lingos for way too long. My...
1
6160
by: maconbot | last post by:
hi all, please exuse my email ">" i am working on location. > hey team, thanks for the quick reply. > > i am trying to parse a pop3 account and populate it into flash. > > the how to code......
6
2961
by: =?Utf-8?B?RGF2aWRN?= | last post by:
Hello, I have an XML file generated from a third party application that I would like to parse. Ideally, I plan on having a windows service setup to scan various folders for XML files and parse the...
2
3225
by: fburn | last post by:
I need some help with an error I'm getting using php 5.2.5 running on linux. I receive an error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or...
11
2904
by: JRough | last post by:
I'm trying to use output buffering to cheat so i can print to excel which is called later than this header(). header("Content-type: application/xmsdownload"); header("Content-Disposition:...
0
7220
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
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7308
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
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
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,...
1
5037
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...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.