Forum Moderators: coopster

Message Too Old, No Replies

syntax error, unexpected T VARIABLE, expecting ',' or ';'

         

mhalverson

9:33 pm on Feb 8, 2012 (gmt 0)

10+ Year Member



Good afternoon

I am very new to php and I am just trying to display 3 fields from a table, but when I try I continue to get the same message:

syntax error, unexpected T_VARIABLE, expecting ',' or ';'connection.php on line 6

My code is listed below. Any help would be appreciated.


<?php
mysql_connect ("domain.com","alumnidba", "password") or die(mysql_error());
echo "Connected to MySQL<br /><hr />";
mysql_select_db ("alumni") or die (mysql_error());
echo "Connected to the Database<br /><hr />"
$sql = 'SELECT `contact` . `lastname` , `contact` . `firstname` , `contact` . `gradyear` '
. ' FROM contact '
. ' ORDER BY `contact` . `lastname` ASC LIMIT 0, 500 ';
?>

g1smd

9:40 pm on Feb 8, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



echo "Connected to the Database<br /><hr />";

When the error is something missing at line 6, look at the end of line 5. :)

mhalverson

9:51 pm on Feb 8, 2012 (gmt 0)

10+ Year Member



Thanks for the help. That worked great. I obviously have no idea what I am doing here. I thought that by writing that code, the data in the table I was trying to get information from would appear on the php page, but it doesn't.

I hate to bother any of you further, but if you have any ideas on how I can display the actual results of my sql query, it would be greatly appreciated.

Thanks

mhalverson

10:17 pm on Feb 8, 2012 (gmt 0)

10+ Year Member



Ok, I got one more step and that is to display the data I wanted to see. Now I just need to get it displayed inside of a table that looks much better than just the data sitting next to each other with a space in between. Any help would really be appreciated.

Thanks

<?php
$host = "domain.com";
$user = "username";
$pass = "password";
$dbname = "alumni";

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);

$sql = 'SELECT `contact` . `lastname` , `contact` . `firstname` , `contact` . `gradyear` '
. ' FROM contact '
. ' ORDER BY `contact` . `lastname` ASC LIMIT 0, 500 ';

$query = mysql_query($sql);

while ($row = mysql_fetch_array($query)) { echo "<p>",$row['lastname']," ",$row['firstname']," ",$row['gradyear']; }
?>

g1smd

11:55 pm on Feb 8, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Once you have it working take a step back and then design the code a slightly different way.

Don't directly write the data to the HTML page, instead store the data in variables or in an array. Do all this stuff at the top of the PHP script. Only once you have done that, send the opening DOCTYPE and <html> tag, and then write out the page of HTML code and content.

You'll then be able to see an easy way to answer the question when it comes, and it will come "how do I return a 404 error when there is no data in the database for the current query?".

It's too late to send the HTTP 404 status code once you have sent the DOCTYPE to the browser. That status code has to be sent in the HTTP header.