j05hr Posted September 17, 2008 Author Share Posted September 17, 2008 i'm really confused as to why this doesn't work Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\widget.corp\includes\connection.php on line 4 content.php: <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?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", "localhost") Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643652 Share on other sites More sharing options...
kenrbnsn Posted September 17, 2008 Share Posted September 17, 2008 You need semi-colons at the end of every line in contants.php <?php // Database Constants define("DB_SERVER", "localhost"); define("DB_USER", "root"); define("DB_PASS", "telephone"); define("DB_NAME", "localhost"); ?> Also, just a styling note -- don't go in/out of php on every line. This: <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php include("includes/header.php"); ?> should be written as <?php require_once("includes/connection.php"); require_once("includes/functions.php"); include("includes/header.php"); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643664 Share on other sites More sharing options...
j05hr Posted September 17, 2008 Author Share Posted September 17, 2008 i done what you said but it now has the exact same error message about line 5 Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643747 Share on other sites More sharing options...
mbrown Posted September 17, 2008 Share Posted September 17, 2008 sorry did not see the replies...the corrections i would of made are already done. i have removed my edits due to that. Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643750 Share on other sites More sharing options...
j05hr Posted September 17, 2008 Author Share Posted September 17, 2008 sorry did not see the replies...the corrections i would of made are already done. i have removed my edits due to that. cheers anyway do you know by default if my username would be root? as i never had to enter it before but now its come up and in the video it's root so i assumed the fault user is root? Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643752 Share on other sites More sharing options...
mbrown Posted September 17, 2008 Share Posted September 17, 2008 sorry did not see the replies...the corrections i would of made are already done. i have removed my edits due to that. cheers anyway do you know by default if my username would be root? as i never had to enter it before but now its come up and in the video it's root so i assumed the fault user is root? for the database -> yes usually in my experience it has been root if you are running on your localhost. if you are running it on a live web server it could by anything from usernametologin_name to just name. You can always double check with your hosting provider to determine that. They should be able to tell you what it is. They would not be able to tell you what the password is if I remember right from experience. Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643753 Share on other sites More sharing options...
j05hr Posted September 17, 2008 Author Share Posted September 17, 2008 yeah i'm using it through local host so it should be root then, how do i check with my service provider? Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643756 Share on other sites More sharing options...
j05hr Posted September 17, 2008 Author Share Posted September 17, 2008 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643764 Share on other sites More sharing options...
Adam Posted September 17, 2008 Share Posted September 17, 2008 With that he means that if you had purchased some web space off a company and they provided your PHP / MySQL .. In that case you could contact them to get the login name, but with what you have installed I can't see no reason why it wouldn't be root at all... ? Does it not work? Adam Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643776 Share on other sites More sharing options...
j05hr Posted September 17, 2008 Author Share Posted September 17, 2008 yeah i know about the online servers, just wasn't sure about if it's localhost whether it is definately root. still doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643781 Share on other sites More sharing options...
Adam Posted September 17, 2008 Share Posted September 17, 2008 Okay, well it should be. Most likely a problem else-where.. what error are you getting? Adam Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643784 Share on other sites More sharing options...
j05hr Posted September 17, 2008 Author Share Posted September 17, 2008 Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\widget.corp\includes\connection.php on line 5 Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643792 Share on other sites More sharing options...
kenrbnsn Posted September 17, 2008 Share Posted September 17, 2008 Parse errors like that usually mean that you are missing a semi-colon on a line before the one that's reported. They can also happen when you don't close a quoted string correctly or strings are not concatenated correctly. Ken Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643833 Share on other sites More sharing options...
j05hr Posted September 17, 2008 Author Share Posted September 17, 2008 these are the three pages i'm using and i can't see any differences between my code and what i'm copying it from 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", "orbeau"); define("DB_NAME", "widget_corp"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643838 Share on other sites More sharing options...
kenrbnsn Posted September 17, 2008 Share Posted September 17, 2008 In connection.php, you are missing the semi-colon on this line: <?php require("constants.php") ?> Don't assume that all code you see in books or in tutorials is correct. Ken Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643850 Share on other sites More sharing options...
j05hr Posted September 17, 2008 Author Share Posted September 17, 2008 it's a video tutorial though where their one definately does work Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-643905 Share on other sites More sharing options...
ratcateme Posted September 17, 2008 Share Posted September 17, 2008 if you are really serious about continuing php you should get a IDE that does syntax highlighting i use phpDesigner it has a build in thing that uses a php.exe to evaluate your code and will report back on all your errors live so you don't miss out random ;'s Scott. Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-644072 Share on other sites More sharing options...
j05hr Posted September 19, 2008 Author Share Posted September 19, 2008 thanks scott that was really helpful i got a new error message away from php i think it's to do with mysql but it confuses me as to why it wouldn't work because i made a table called subjects. the error message: "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 <?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 ($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()); } 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-645293 Share on other sites More sharing options...
ratcateme Posted September 20, 2008 Share Posted September 20, 2008 while ($row = mysql_fetch_array($result)) { $result should be $subject_set Scott. Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-646139 Share on other sites More sharing options...
j05hr Posted September 22, 2008 Author Share Posted September 22, 2008 i've finished the tutorial and now want to incorporate it into my website. my question is how do you upload it onto an online server? you don't just upload it to your ftp do you? Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-648233 Share on other sites More sharing options...
DarkWater Posted September 23, 2008 Share Posted September 23, 2008 Yeah, you do. Do you already have web hosting with PHP? Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-648279 Share on other sites More sharing options...
Lee-Bartlett Posted September 23, 2008 Share Posted September 23, 2008 Are the the lynda.com tutorials? i got stuck on them, i copied his code etc exact and didnt work to Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-648286 Share on other sites More sharing options...
Adam Posted September 23, 2008 Share Posted September 23, 2008 By the way in connection.php, this line has an extra bracket on the end: $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS)); should be: $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS); Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-648293 Share on other sites More sharing options...
j05hr Posted September 24, 2008 Author Share Posted September 24, 2008 I asked my provider if i had web hosting with php to which he replied. Yes, PHP is supported on your plan and you do not have to do anything as I have installed the PHP valueapp for you. So does this mean i can just load the php file into my ftp? And if so where does the data go when someone submits a form? Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-649435 Share on other sites More sharing options...
j05hr Posted September 24, 2008 Author Share Posted September 24, 2008 Are the the lynda.com tutorials? i got stuck on them, i copied his code etc exact and didnt work to yeah it's the lynda.com tutorials, it's very good but he goes through it so fast and someone like me trying to learn it as a beginner is very confusing but got there in the end Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/page/2/#findComment-649441 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.