Forum Moderators: coopster

Message Too Old, No Replies

unexpected T VARIABLE

         

j05hr

4:18 pm on Sep 18, 2008 (gmt 0)

10+ Year Member



i'm new to php and trying to learn it via a video tutorial (called PHP With MySQL Essential Training) at the moment i'm making an online login for staff for a webpage.

here is the error message i'm getting

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\widget.corp\includes\connection.php on line 5

and this is the code

content.php:

<?php
require_once("includes/connection.php");
require_once("includes/functions.php");
include("includes/header.php");
?>
<table id="structure">
<tr>
<td id="navigation">
<ul class=>"subjects">
<?php

$subject_set = mysql_query("SELECT * FROM subjects", $connection);
if(!$subject_set) {
die("Database query failed: " . mysql_error());
}

while ($subject = mysql_fetch_array($subject_set)) {
echo "<li>{$subject["menu_name"]}</li>";
$page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject["id"]}", $connection);
if(!$result) {
die("Database query failed: " . mysql_error());
}

echo "<ul class=\ \"pages\">";
while ($page = mysql_fetch_array($page_set)) {
echo "<li>{$page["menu_name"]}</li>";
}
echo "</ul>";

}

?>
</ul>
</td>
<td id="page">
<h2>Content Area</h2>

</td>
</tr>
</table>
<?php include("includes/footer.php"); ?>

connection.php

<?php
require("constants.php")

// 1. create a database connection
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS));
if(!$connection) {
die("Database connection failed: " .mysql_error());
}

// 2. Select a database to use
$db_select = mysql_select_db("DB_NAME",$connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
?>

constants.php

<?php

// Database Constants
define("DB_SERVER", "localhost");
define("DB_USER", "root");
define("DB_PASS", "telephone");
define("DB_NAME", "widget_corp");

?>

any help will be much appreciated

daveginorge

4:50 pm on Sep 18, 2008 (gmt 0)

10+ Year Member



You missed the ; at the end of line 4
4. require("constants.php")

Errors quiet often reflect to the line before.

Dave

j05hr

5:10 pm on Sep 18, 2008 (gmt 0)

10+ Year Member



sorry so where am i putting the ;?

Anyango

5:15 pm on Sep 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



as Dave mentioned, after this

require("constants.php")

make that line, this

require("constants.php");

j05hr

5:29 pm on Sep 18, 2008 (gmt 0)

10+ Year Member



that is now changed i'm now getting the error

Parse error: syntax error, unexpected ')' in C:\wamp\www\widget.corp\includes\connection.php on line 4

Anyango

5:33 pm on Sep 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



in connection.php, there is an extra ) at the end of this line

$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS));

it should be

$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);

j05hr

5:41 pm on Sep 18, 2008 (gmt 0)

10+ Year Member



now it's saying

Database selection failed: Unknown database 'db_name'

in the constants.php doesn't that make the username widget_corp?

Anyango

5:44 pm on Sep 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



remove Double quotes around DB_NAME

this
$db_select = mysql_select_db("DB_NAME",$connection);

should be

$db_select = mysql_select_db(DB_NAME,$connection);

j05hr

7:01 pm on Sep 18, 2008 (gmt 0)

10+ Year Member



now that's connected it

i now get the error message

# "subjects"> About Widget Corp
Database query fail:

which i'm pretty sure is coming from here:

while ($subject = mysql_fetch_array($subject_set)) {
echo "<li>{$subject["menu_name"]}</li>";
$page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject["id"]}", $connection);
if(!$result) {
die("Database query fail: " . mysql_error());

if you can see any errors in there?

jatar_k

12:10 am on Sep 19, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



there are at least a few typos in the html you could fix

as for your query fail you can do a few things

add a specific message in each or die statement so you don't need to guess which query is dying

when you figure out which one is dying and then, since you are creating your queries dynamically, output the created query to see if the problem is there

you also need to change the way you set this up

$page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject["id"]}", $connection);
if(!$result) {
die("Database query fail: " . mysql_error());

to

$page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject["id"]}", $connection) or die("Database query fail: " . mysql_error());

i think that's why you aren't getting an error output, but I could be wrong

j05hr

1:05 am on Sep 19, 2008 (gmt 0)

10+ Year Member



finally fixed that error but now getting an error message saying

"subjects">
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\widget.corp\content.php on line 17

which i'm not sure about as i created a table in sql called subjects?

the code from line 12 - 21:

$subject_set = mysql_query("SELECT * FROM subjects", $connection);
if(!$subject_set) {
die("Database query failed: " . mysql_error());
}

while ($row = mysql_fetch_array($result)) {
echo "<li>{$row["menu_name"]}</li>";
$result = mysql_query("SELECT * FROM pages". $connection);
if (!$result) {
die("Database query failed: " .mysql_error());

Anyango

4:58 am on Sep 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



maybe you'r just looking for a fix and not learning..

$subject_set = mysql_query("SELECT * FROM subjects", $connection);
if(!$subject_set) {
die("Database query failed: " . mysql_error());
}

while ($row = mysql_fetch_array($subject_set))
{
echo "<li>{$row["menu_name"]}</li>";
$result = mysql_query("SELECT * FROM pages". $connection);
if (!$result)
{
die("Database query failed: " .mysql_error());

j05hr

6:32 am on Sep 19, 2008 (gmt 0)

10+ Year Member



well i'm just starting out at the moment so it's all about copying and finding the errors correcting them and then when it's all done going back to do it a second time to actually learn how it was done

with your code, it gets rid of the css and tries to find a page called pagesresource.php?