j05hr Posted September 12, 2008 Share Posted September 12, 2008 i'm new to php following a video tutorial.. using notepad they type in a php code that should say hello world on the webpage. when a copy the code mine doesn't come up with the code <html> <head> <title>Hello World!</title> </head> <body> <?php echo "hello World!"; ?> </body> </html> would anybody be able to tell me why it doesn't work? thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/ Share on other sites More sharing options...
ratcateme Posted September 12, 2008 Share Posted September 12, 2008 are you running it on a php server? Scott. Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640200 Share on other sites More sharing options...
j05hr Posted September 13, 2008 Author Share Posted September 13, 2008 on my local machine if that helps your question? Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640201 Share on other sites More sharing options...
ratcateme Posted September 13, 2008 Share Posted September 13, 2008 have you install php and apache or iis? or are you loading the file by going C:\php\file.php in internet explorer? Scott. Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640205 Share on other sites More sharing options...
j05hr Posted September 13, 2008 Author Share Posted September 13, 2008 i've gpt apache - i downloaded wampserver with apache php and MySQL when i view it the file path is: file:///C:/wamp/www/php_sandbox/helloworld1.php Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640206 Share on other sites More sharing options...
ratcateme Posted September 13, 2008 Share Posted September 13, 2008 you need to go to http://localhost/helloworld1.php Scott. Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640210 Share on other sites More sharing options...
j05hr Posted September 13, 2008 Author Share Posted September 13, 2008 it said it wasnt found i guess i have to upload it? how would i do that? Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640211 Share on other sites More sharing options...
ratcateme Posted September 13, 2008 Share Posted September 13, 2008 no you dont upload it go to http://localhost/ and see what you get also try going to http://localhost/php_sandbox/helloworld1.php Scott. Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640212 Share on other sites More sharing options...
j05hr Posted September 13, 2008 Author Share Posted September 13, 2008 thanks, that worked, i thought it would be a case of just opening as you would a normal html file Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640213 Share on other sites More sharing options...
DarkWater Posted September 13, 2008 Share Posted September 13, 2008 No, it's not. This is because Apache needs to tell the PHP interpreter to run the code. Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640221 Share on other sites More sharing options...
j05hr Posted September 13, 2008 Author Share Posted September 13, 2008 i understand now..i've just finished college and plan on doing web design and just trying to learn everything through online videos. the help is much appreciated thanks Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640225 Share on other sites More sharing options...
DarkWater Posted September 13, 2008 Share Posted September 13, 2008 i understand now..i've just finished college and plan on doing web design and just trying to learn everything through online videos. the help is much appreciated thanks You'll find a lot more information in tutorials and books. One piece of advice though: Don't copy tutorials code for code. Then you have no idea what you just did. Use tutorials to introduce new concepts, not copy from. Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640228 Share on other sites More sharing options...
j05hr Posted September 13, 2008 Author Share Posted September 13, 2008 it's very good, it goes through every little detail, you might of even heard of it before PHP with MySQL Essential Training do you mean write the code down yourself? Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640230 Share on other sites More sharing options...
dropfaith Posted September 13, 2008 Share Posted September 13, 2008 http://www.tizag.com/phpT/ is a good php start Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640232 Share on other sites More sharing options...
ratcateme Posted September 13, 2008 Share Posted September 13, 2008 and remember that php.net is your best friend have a look around and learn how the manual is set out as it is a new developers best tool in the war on web development. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640239 Share on other sites More sharing options...
j05hr Posted September 13, 2008 Author Share Posted September 13, 2008 thanks, any other tips? Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640245 Share on other sites More sharing options...
j05hr Posted September 13, 2008 Author Share Posted September 13, 2008 learning about variables now and stumbled across an error. i copied the code letter for letter from the code but mine comes up with an error. here's my code <html> <head> <title>Variables</title> <head> <body> <?PHP $var1 = 10; echo $var1; $my_variable = "hello world"; $my_Variable = "hello world again"; echo $my_variable echo "br />"; $var1 = 100 echo $var1; ?> </body> </html> and this is the error message Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in C:\wamp\www\php_sandbox\variables1.php on line 12 my code is exactly the same as the other persons so i cant see what's wrong Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640260 Share on other sites More sharing options...
DarkWater Posted September 13, 2008 Share Posted September 13, 2008 You missed a ; after "echo $my_variable". Also, I may just be nitpicking, but make the opening PHP tag lowercase. Uppercase just seems so weird. Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640262 Share on other sites More sharing options...
j05hr Posted September 13, 2008 Author Share Posted September 13, 2008 i corrected that now but it didn't fix it, i'm now getting an error code saying Parse error: syntax error, unexpected T_ECHO in C:\wamp\www\php_sandbox\variables1.php on line 14 i may be wrong but i think its something to do with duplicating the $var1 because when i take that out it works fine and as for the php being in uppercase i'm a complete noob so all constructive criticism is welcome Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640263 Share on other sites More sharing options...
DarkWater Posted September 13, 2008 Share Posted September 13, 2008 You missed another ; after "$var1 = 100". Semicolons go at the end of basically ever line of code (except for certain things like loops). Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640264 Share on other sites More sharing options...
j05hr Posted September 13, 2008 Author Share Posted September 13, 2008 thanks i actually had that Semicolon there originally while i typed it in notepad then i put it in to retype it again to see if it could find the error and must of left it off Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-640267 Share on other sites More sharing options...
j05hr Posted September 17, 2008 Author Share Posted September 17, 2008 i'm back again, building a content management system and come up with this error code Warning: require(constants.php) [function.require]: failed to open stream: No such file or directory in C:\wamp\www\widget.corp\includes\connection.php on line 2 Fatal error: require() [function.require]: Failed opening required 'constants.php' (include_path='.;C:\php5\pear') in C:\wamp\www\widget.corp\includes\connection.php on line 2 i been trying to solve it for about half an hour but can't see whats wrong, the code is <?php $connection = mysql_connect("localhost", "root", "telephone"); if (!$connection) { die("Database connection failed: " . mysql_error()); } // 2. Select a database to use $db_select = mysql_select_db("widget_corp",$connection); if (!$db_select) { die("Database selection failed: " . mysql_error()); } ?> <?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 // 3. perform database query $subject_set = mysql_query("SELECT * FROM subjects", $connection); if (!$result) { 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={$row["id"]}", $connection); if (!$page_set) { 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 require("includes/footer.php"); ?> any help much appreciated thanks Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-643415 Share on other sites More sharing options...
kenrbnsn Posted September 17, 2008 Share Posted September 17, 2008 In line 2 of connections.php you're trying to include the file constants.php. This file isn't there. Ken Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-643419 Share on other sites More sharing options...
j05hr Posted September 17, 2008 Author Share Posted September 17, 2008 new error message Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\wamp\www\widget.corp\content.php on line 22 <?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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-643599 Share on other sites More sharing options...
ratcateme Posted September 17, 2008 Share Posted September 17, 2008 you need to escape double quotes in a string that is defined inside double quotes so this echo "<ul class=\ "pages">"; becomes echo "<ul class=\ \"pages\">"; Scott. Quote Link to comment https://forums.phpfreaks.com/topic/124009-learning-php/#findComment-643615 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.