Page 1 of 1
Simple SELECT statement
Posted: Mon Feb 11, 2008 4:03 pm
by jbriskin
The following code is just for testing... not worried about security etc at this point...
All I want to do is select all the records from a table and display the results.
my code is:
Code: Select all
<?php
$doc_root = $_SERVER['DOCUMENT_ROOT'];
include("$doc_root/constants.php");
mysql_connect ($db_host, $db_user, $db_pass);
mysql_select_db ($db_name);
$query = "SELECT * FROM formsubmit";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
while ($row = mysql_fetch_assoc($result)) {
echo $row['timeStamp'];
echo $row['NameFirst'];
echo $row['NameLast'];
echo $row['NameCompany'];
echo $row['Address01'];
echo $row['Address02'];
echo $row['City'];
echo $row['State'];
echo $row['ZipCode'];
echo $row['Email'];
echo $row['PhoneWork'];
echo $row['PhoneCell'];
echo $row['PhoneFax'];
echo $row['Comments'];
echo $row['RemoteAddress'];
}
//mysql_free_result($result);
?>
My result is:
Code: Select all
Parse error: parse error, unexpected T_STRING in FormData.php on line 11
What am I missing?
Re: Simple SELECT statement
Posted: Mon Feb 11, 2008 6:37 pm
by Stryks
Good question actually. I only have time for a quick glance, but I cant see it.
Maybe a silly question, but you're sure that is FormData.php you posted?
Also, I believe that you need to remove line 10 to prevent discarding the first returned row of data.
Re: Simple SELECT statement
Posted: Mon Feb 11, 2008 6:53 pm
by jbriskin
Yes, that is FormData.php... was suppose to be a quick test... but it is now not quick and seems to test only that I am not a php coder.
I got the syntax online from a sample. I just made it point to my specifics. I don't really understand all of what it is doing... but it looks straight forward.. but line 10 is suspicious now that you point it out...
Re: Simple SELECT statement
Posted: Mon Feb 11, 2008 7:00 pm
by John Cartwright
The error most likely exists on your included files.. there certainly is no parse error on the code you've posted.
Re: Simple SELECT statement
Posted: Mon Feb 11, 2008 8:05 pm
by jbriskin
Jcart wrote:The error most likely exists on your included files.. there certainly is no parse error on the code you've posted.
There is some HTML Style tags in the constants.php... I guess that could be an issue... otherwise it is just a bunch of variables... that have been in use for about a year... but it is worth checking out.... thank you.
Re: Simple SELECT statement
Posted: Mon Feb 11, 2008 8:21 pm
by jbriskin
I pulled out the includes now the code looks like this:
Code: Select all
<?php
$db_host = 'my.server.net';
$db_name = 'myDataBase';
$db_user = 'myUser';
$db_pass = 'myPass';
mysql_connect ($db_host, $db_user, $db_pass);
mysql_select_db ($db_name);
$query = "SELECT * FROM formsubmit";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
while ($row = mysql_fetch_assoc($result)) {
echo $row['timeStamp'];
echo $row['NameFirst'];
echo $row['NameLast'];
echo $row['NameCompany'];
echo $row['Address01'];
echo $row['Address02'];
echo $row['City'];
echo $row['State'];
echo $row['ZipCode'];
echo $row['Email'];
echo $row['PhoneWork'];
echo $row['PhoneCell'];
echo $row['PhoneFax'];
echo $row['Comments'];
echo $row['RemoteAddress'];
}
?>
And my result is:
Code: Select all
Parse error: parse error, unexpected T_STRING in FormData.php on line 11
To state the obvious, I don't get it...
Re: Simple SELECT statement
Posted: Mon Feb 11, 2008 9:56 pm
by Festy
Is multiple declaration of $row on line 10 and 11 causing the problem?

I'm not sure though.
Re: Simple SELECT statement
Posted: Mon Feb 11, 2008 10:06 pm
by s.dot
jbriskin wrote:I pulled out the includes now the code looks like this:
Code: Select all
<?php
$db_host = 'my.server.net';
$db_name = 'myDataBase';
$db_user = 'myUser';
$db_pass = 'myPass';
mysql_connect ($db_host, $db_user, $db_pass);
mysql_select_db ($db_name);
$query = "SELECT * FROM formsubmit";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
while ($row = mysql_fetch_assoc($result)) {
echo $row['timeStamp'];
echo $row['NameFirst'];
echo $row['NameLast'];
echo $row['NameCompany'];
echo $row['Address01'];
echo $row['Address02'];
echo $row['City'];
echo $row['State'];
echo $row['ZipCode'];
echo $row['Email'];
echo $row['PhoneWork'];
echo $row['PhoneCell'];
echo $row['PhoneFax'];
echo $row['Comments'];
echo $row['RemoteAddress'];
}
?>
And my result is:
Code: Select all
Parse error: parse error, unexpected T_STRING in FormData.php on line 11
To state the obvious, I don't get it...
In this EXACT code that you've posted, there aren't any parsing errors. I've copied it into my editor and ran it on localhost in my web browser. The results?
Code: Select all
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'my.server.net' (11004) in C:\Apache2\Apache2\htdocs\crap\testing.php on line 6
Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Apache2\Apache2\htdocs\crap\testing.php on line 7
Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\Apache2\Apache2\htdocs\crap\testing.php on line 7
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Apache2\Apache2\htdocs\crap\testing.php on line 9
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\Apache2\Apache2\htdocs\crap\testing.php on line 9
Access denied for user 'ODBC'@'localhost' (using password: NO)
Those errors are just because I don't have the database set up.

It got past the parser so there's no parsing errors. Perhaps an include or something is causing the error. The file that the error is on is
formData.php. Are you sure you're posting the formData.php code?
Re: Simple SELECT statement
Posted: Mon Feb 11, 2008 10:40 pm
by Stryks
Just for fun, create a new file and copy the code as last posted (with the includes removed) into it, save and give it a run.
Re: Simple SELECT statement
Posted: Mon Feb 11, 2008 11:06 pm
by jbriskin
ok... very odd. Starting at line 10, none of the spaces are actually spaces. I turned on "show hidden characters" and what should be spaces are not denoted the same way as actual spaces. I guess I could throw it in a hex reader and find out but ....
So anyway, thanks to everyone showing me the actual code was right... I simply deleted the bad "spaces" and replaced them with good "spaces"... Now it works. As expected...
Again, thanks for the help on getting my first ever select statement to work...
Re: Simple SELECT statement
Posted: Tue Feb 12, 2008 12:48 am
by s.dot
I suspect you're using a bad editor.. such as one that inserts hidden characters.
Re: Simple SELECT statement
Posted: Tue Feb 12, 2008 11:20 am
by jbriskin
I use bbedit. The code that had the bad spaces was cut and paste from the web. The code I typed out myself had no issues... but I'll leave the option for showing hidden characters on for a bit.