For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > May 2004 > Newbie question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Newbie question
Ross Contino

2004-05-16, 12:30 am

Hello:

I am trying to post a record to a mySQL table from PHP. I am very new to PHP. With the following code I get the error: "Parse error: parse error, unexpected T_VARIABLE in c:\www\signouts\checkdate.php on line 37." From what I have read, this is typically a error produced from a typographical error. I cannot find an error. The string fields have been passed to the PHP script and I can print them to the screen, but cannot seem to save them in the record. apache is active, mySQL is active and both are running properly. What have I done wrong?? (see code below).




//enter the save data here
//make datebase connection
$conn = mysql_connect("localhost", "root", "");
$select = mysql_select_db("docdir", $conn);
$sql = "INSERT INTO signouts(Doc_Covering,Doc_Out,Start_Time
,End_Time) values('$DocOn','$DocOut','$TimeOut','$T
imeBack');"
$result = mysql_query($sql); //This is line 37 in my program
if ($result){
print "<h3>$DocOn has been successfully updated!</h3>\n";
}else{
print "<h3>There was a problem saving the record</h3>\n";
}

Michael Vilain

2004-05-16, 1:30 am

In article <10adn3iqa9lpdf2@corp.supernews.com>,
"Ross Contino" <rosscontino@suscom.net> wrote:

> Hello:
>
> I am trying to post a record to a mySQL table from PHP. I am very new to
> PHP. With the following code I get the error: "Parse error: parse error,
> unexpected T VARIABLE in c:\www\signouts\checkdate.php on line 37." From
> what I have read, this is typically a error produced from a typographical
> error. I cannot find an error. The string fields have been passed to the
> PHP script and I can print them to the screen, but cannot seem to save them
> in the record. apache is active, mySQL is active and both are running
> properly. What have I done wrong?? (see code below).
>
>
>
>
> //enter the save data here
> //make datebase connection
> $conn = mysql connect("localhost", "root", "");
> $select = mysql select db("docdir", $conn);
> $sql = "INSERT INTO signouts(Doc Covering,Doc Out,Start Time,End
> Time) values('$DocOn','$DocOut','$TimeOut','$T
imeBack');"
> $result = mysql query($sql); //This is line 37 in my program
> if ($result){
> print "<h3>$DocOn has been successfully updated!</h3>\n";
> }else{
> print "<h3>There was a problem saving the record</h3>\n";
> }


I thought the column names for a database couldn't contain spaces. If
they do, don't you put them inside backticks to ensure the SQL parser
doesn't barf on them? Also, Isn't the query function "mysql_query".

Looks like you need to get a book on PHP and MySQL...

--
DeeDee, don't press that button! DeeDee! NO! Dee...



the reporter

2004-05-16, 1:30 am

Hi Ross,

Problem solved. Copy and paste this. It's Line 36 that gives you problem. You put the ; in the wrong place. Furthermore, you don't need ; within SQL statement, if it's only 1 liner.

The Reporter
No Nonense


$conn = mysql_connect("localhost", "root", "");
$select = mysql_select_db("docdir", $conn);
$sql = "INSERT INTO signouts(Doc_Covering,Doc_Out,Start_Time
,End_Time) values('$DocOn','$DocOut','$TimeOut','$T
imeBack')";
$result = mysql_query($sql); //This is line 37 in my program
if ($result){
print "<h3>$DocOn has been successfully updated!</h3>\n";
}else{
print "<h3>There was a problem saving the record</h3>\n";
}





"Ross Contino" <rosscontino@suscom.net> wrote in message news:10adn3iqa9lpdf2@corp.supernews.com...
Hello:

I am trying to post a record to a mySQL table from PHP. I am very new to PHP. With the following code I get the error: "Parse error: parse error, unexpected T_VARIABLE in c:\www\signouts\checkdate.php on line 37." From what I have read, this is typically a error produced from a typographical error. I cannot find an error. The string fields have been passed to the PHP script and I can print them to the screen, but cannot seem to save them in the record. apache is active, mySQL is active and both are running properly. What have I done wrong?? (see code below).




//enter the save data here
//make datebase connection
$conn = mysql_connect("localhost", "root", "");
$select = mysql_select_db("docdir", $conn);
$sql = "INSERT INTO signouts(Doc_Covering,Doc_Out,Start_Time
,End_Time) values('$DocOn','$DocOut','$TimeOut','$T
imeBack');"
$result = mysql_query($sql); //This is line 37 in my program
if ($result){
print "<h3>$DocOn has been successfully updated!</h3>\n";
}else{
print "<h3>There was a problem saving the record</h3>\n";
}

Theo

2004-05-16, 1:30 am

"Michael Vilain <vilain@spamcop.net>" wrote in news:vilain-
133F1B.21320515052004@comcast.dca.giganews.com:

> Also, Isn't the query function "mysql_query".


yes
Tom Thackrey

2004-05-16, 1:30 am


On 15-May-2004, "Ross Contino" <rosscontino@suscom.net> wrote:

> I am trying to post a record to a mySQL table from PHP. I am very new to
> PHP. With the following code I get the error: "Parse error: parse
> error, unexpected T_VARIABLE in c:\www\signouts\checkdate.php on line 37."
> From what I have read, this is typically a error produced from a
> typographical error. I cannot find an error. The string fields have been
> passed to the PHP script and I can print them to the screen, but cannot
> seem to save them in the record. apache is active, mySQL is active and
> both are running properly. What have I done wrong?? (see code below).
>
>
>
>
> //enter the save data here
> //make datebase connection
> $conn = mysql_connect("localhost", "root", "");
> $select = mysql_select_db("docdir", $conn);
> $sql = "INSERT INTO
> signouts(Doc_Covering,Doc_Out,Start_Time
,End_Time)
> values('$DocOn','$DocOut','$TimeOut','$T
imeBack');"
> $result = mysql_query($sql); //This is line 37 in my program
> if ($result){
> print "<h3>$DocOn has been successfully updated!</h3>\n";
> }else{
> print "<h3>There was a problem saving the record</h3>\n";
> }


In line 36 you have the ; inside the "s, so line 36 does not end with a ;.

The line number in error messages refers to the line where the error was
detected. The line causing the error is often before the line reported. The
particular error you got is almost always caused by a missing ; or
unbalanced quotes or brackets.

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to jamesbutler@willglen.net (it's reserved for spammers)
Sadara

2004-05-16, 9:30 am



Ross Contino wrote:
> Hello:
>
> I am trying to post a record to a mySQL table from PHP. I am very new
> to PHP. With the following code I get the error: *"Parse error*:
> parse error, unexpected T_VARIABLE in *c:\www\signouts\checkdate.php* on
> line *37*." From what I have read, this is typically a error produced
> from a typographical error. I cannot find an error. The string fields
> have been passed to the PHP script and I can print them to the screen,
> but cannot seem to save them in the record. apache is active, mySQL is
> active and both are running properly. What have I done wrong?? (see
> code below).
>
>
>
>
> //enter the save data here
> //make datebase connection
> $conn = mysql_connect("localhost", "root", "");
> $select = mysql_select_db("docdir", $conn);
> $sql = "INSERT INTO
> signouts(Doc_Covering,Doc_Out,Start_Time
,End_Time)
> values('$DocOn','$DocOut','$TimeOut','$T
imeBack');"
> $result = mysql_query($sql); //This is line 37 in my program
> if ($result){
> print "<h3>$DocOn has been successfully updated!</h3>\n";
> }else{
> print "<h3>There was a problem saving the record</h3>\n";
> }

the problem is at the end of line 36. as it is at the moment, the
command on line 36 is not terminated, as the semi-colon is INSIDE the
$sql string.

,'$TimeBack');"

should be:

,'$TimeBack')";

it took me a long time to see that!

ara

Ross Contino

2004-05-16, 9:30 am

I have underscores in all those fields. I guess when I cut and pasted, the
underscores did not paste. Same for the mysql_query function. Sorry about
that.

Thanks,
Ross

<Michael Vilain <vilain@spamcop.net>> wrote in message
news:vilain-133F1B.21320515052004@comcast.dca.giganews.com...
> In article <10adn3iqa9lpdf2@corp.supernews.com>,
> "Ross Contino" <rosscontino@suscom.net> wrote:
>
to[color=darkred]
error,[color=darkred]
From[color=darkred]
typographical[color=darkred]
the[color=darkred]
them[color=darkred]
Time,End[color=darkred]
program[color=darkred]
>
> I thought the column names for a database couldn't contain spaces. If
> they do, don't you put them inside backticks to ensure the SQL parser
> doesn't barf on them? Also, Isn't the query function "mysql_query".
>
> Looks like you need to get a book on PHP and MySQL...
>
> --
> DeeDee, don't press that button! DeeDee! NO! Dee...
>
>
>



Ross Contino

2004-05-16, 10:30 am

Thanks! Simple stuff and I had it screwed up! Thanks again.

Ross

"Sadara" <araNOWAY@NOWAYdds.nl> wrote in message
news:40a760c2$0$557$e4fe514c@news.xs4all.nl...
>
>
> Ross Contino wrote:
program[color=darkred]
> the problem is at the end of line 36. as it is at the moment, the
> command on line 36 is not terminated, as the semi-colon is INSIDE the
> $sql string.
>
> ,'$TimeBack');"
>
> should be:
>
> ,'$TimeBack')";
>
> it took me a long time to see that!
>
> ara
>



Lol Zimmerli

2004-05-17, 11:33 am

Hello,

Sadara <araNOWAY@NOWAYdds.nl> =E9crit/wrote:
>=20
> it took me a long time to see that!


You would have seen it in one second with an editor that colorize
syntax :)

--=20
Lol Zimmerli - http://www.lzi.ch/lol/
RootShell

2004-05-18, 8:30 pm

"Ross Contino" <rosscontino@suscom.net> wrote in message
news:10aepcci7erto6c@corp.supernews.com...
> Thanks! Simple stuff and I had it screwed up! Thanks again.
>
> Ross
>
> "Sadara" <araNOWAY@NOWAYdds.nl> wrote in message
> news:40a760c2$0$557$e4fe514c@news.xs4all.nl...
on[color=darkred]
fields[color=darkred]
is[color=darkred]
> program
updated!</h3>\n";[color=darkred]
record</h3>\n";[color=darkred]
>
>


Im ALSO NEW to PHP but i learned already something that i guess everyone
will agree with me on:

*** ALWAYS double check the previous and the line from where PHP reports the
error from. ***

Is this a important stattement or not? :)

Regards,
RootShell




Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com