...

View Full Version : parse error, unexpected T_ENCAPSED_AND_WHITESPACE



hmg
04-29-2006, 04:50 PM
I am pretty new to PHP, and need some help.

I am getting the following error:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in ... on line 26

The script that I am having a problem with follows:

<?php
$host = "localhost";
$login_name = "hmg";
$password = "passhmg";

//Connecting to MYSQL
$link=MySQL_connect("$host","$login_name","$password");

//Select the database we want to use
MySQL_select_db("mydb",$link) or die("Could not select database");
$date=$_POST['orderdate'];
$result = mysql_query("SELECT max(event_num) FROM events WHERE date = '$date', $link);

$num_rows = mysql_num_rows($result);

//Code to check if statement executed properly increment event_num if found
if ($num_rows > 0 )
{
$maxevt = mysql_result($result,0)
$event_num = $maxevt + 1;
} else {
$event_num = 1;
}
$short_desc=$_POST['ShortDesc'];
$long_desc=$_POST['LongDesc'];

//Name query $sql
$sql = "INSERT INTO events (date, event_num, short_desc, long_desc) VALUES ('$date', '$event_num', '$short_desc', '$long_desc')";


//Execute query and get result
$result = mysql_query($sql);


//Code to check if statement executed properly and display MailUpd.htm
if ($result) {
echo "<script>alert('Information updated')</script>";
} else {
$db_error = mysql_error();
echo("An error has occured: $db_error");
}
mysql_close($link);
?>

mobilehell
04-29-2006, 05:53 PM
this line u forgot to close with "
should be

$result = mysql_query("SELECT max(event_num) FROM events WHERE date = '$date', $link");
instead of

$result = mysql_query("SELECT max(event_num) FROM events WHERE date = '$date', $link);

:)

hmg
04-29-2006, 06:38 PM
Thanks!

I copied the script from an earlier one I had written and accidentally deleted the quote.

For future reference, did you just review the code by eye or is there some other trick to find these types of errors?

GJay
04-29-2006, 06:50 PM
$result = mysql_query("SELECT max(event_num) FROM events WHERE date = '$date', $link);

$num_rows = mysql_num_rows($result);


if you enclose code in [php ] tags (without the space...) then it highlights the code, making it obvious you missed something. You can text text-editors that understand PHP, and can highlight accordingly- might be worth using one.

hmg
04-29-2006, 07:11 PM
The editor that I use does highlights key words,etc. in HTML, PHP, ASP etc., but not syntactic errors. Could you suggest a better editor that highlights these errors?

BTW, the script (evtinp.php) is initiated from a different HTML page with: Method="post" action="evtinp.php". However, this causes the alert box (Information updated) after update to appear on a blank screen, rather than the initiating HTML page. I've tried combining the two (HTML and PHP script) into one PHP file with the HTML first, followed by the PHP code with </body> ending the HTML and <?php
beginning the PHP. This causes the Insert to automatically execute with blank data.

How can I get the alert box to appear on the HTML page after the Insert has taken place?

mobilehell
04-29-2006, 07:28 PM
you can put both in the php by checking if data has been posted



<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
The code you just posted here
}
else {
?>
YOUR HTML HERE
<?php
}
?>


btw dreamweaver is pretty neat for php

hmg
04-29-2006, 08:05 PM
Thanks. I now have both files combined into one, but the alert box is still appearing on a blank screen.

The code from the bootom of the PHP through the beginning of the HTML looks like this:

//Name query $sql
$sql = "INSERT INTO events (date, event_num, short_desc, long_desc) VALUES ('$date', '$event_num', '$short_desc', '$long_desc')";


//Execute query and get result
$result = mysql_query($sql);


//Code to check if statement executed properly and display alert box
if ($result) {
echo "<script>alert('Information updated')</script>";
} else {
$db_error = mysql_error();
echo("An error has occured: $db_error");
}
mysql_close($link);
}
else {
?>
<html>
<head>
<title>Enter Calendar Items</title>

.
.

Can I get the alert box ,i.e. alert('Information updated'), to appear on the HTML page.

Thanks..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum