By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

parse error in nested query - please help.

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
'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 discussion thread is closed

Replies have been disabled for this discussion.