Noxin Posted December 11, 2014 Share Posted December 11, 2014 I was reading how to do some beginner stuff in PHP so this to you guys is easy right? Why dosent the code work properly? And or am I trying stuff that is to advanced for a total noob?? this is the php code from the tutorial: <?php $myname = 'Noxin'; and echo '<p>This is PHP</p>'; echo "<p>My name is $myname</p>" echo '<p>My name in another notation is still '.$myname.'</p>'; ?> This is what appears on my localhost: Parse error: syntax error, unexpected 'and' (T_LOGICAL_AND) in C:\Users\RoSeAnN\Desktop\Web Designing\server\htdocs\Practice.php on line 3 Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/ Share on other sites More sharing options...
Noxin Posted December 11, 2014 Author Share Posted December 11, 2014 Sorry resolved line 3 issue changed line 3 to echo. now the problem is line 4 Parse error: syntax error, unexpected 'echo' (T_ECHO) in C:\Users\RoSeAnN\Desktop\Web Designing\server\htdocs\Practice.php on line 4 Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/#findComment-1499252 Share on other sites More sharing options...
Noxin Posted December 11, 2014 Author Share Posted December 11, 2014 Boooo! ok so ive solved some of the issues but the new problem is dosent show everything I Wish it to show this is the new layout; <?php $myname = 'Noxin'; echo '<p>This is PHP</p>'; "<p>My name is $myname</p>"; '<p>My name in another notation is still '.$myname.'</p>'; ?> and this is all that shows on the localhost page This is PHP how to get the rest of the code to come out? Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/#findComment-1499254 Share on other sites More sharing options...
Noxin Posted December 11, 2014 Author Share Posted December 11, 2014 LoL final reply to my own post tonight code is this <?php $myname = 'Noxin'; echo '<p>This is PHP</p>'; "<p>My name is $myname</p>" '<p>My name in another notation is still '.$myname.'</p>'; ?> new error Parse error: syntax error, unexpected ''<p>My name in another notatio' (T_CONSTANT_ENCAPSED_STRING) in C:\Users\RoSeAnN\Desktop\Web Designing\server\htdocs\Practice.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/#findComment-1499255 Share on other sites More sharing options...
NotionCommotion Posted December 11, 2014 Share Posted December 11, 2014 (edited) Good news is usually PHP provides more guidance regarding errors. Bad news is when you are just starting off, you will get a bunch of these. At first, try to keep your echo's small and don't mix single and double quotes. I always "just because" put parenthesis around the stuff I want to echo. Know that a semicolon is "mostly" end of command, and keep an eye out for them. Use a dot (.) to join stuff. <?php $myname = 'Noxin'; echo '<p>This is PHP</p>'. "<p>My name is $myname</p>". '<p>My name in another notation is still '.$myname.'</p>'; ?> PS. See http://php.net/manual/en/language.types.string.php Also, I would probably use the following even though the curly brackets are not required: echo("<p>This is PHP</p><p>My name is {$myname}</p><p>My name in another notation is still {$myname}</p>"); Edited December 11, 2014 by NotionCommotion Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/#findComment-1499256 Share on other sites More sharing options...
LeJack Posted December 11, 2014 Share Posted December 11, 2014 Like Notion said. I think this would also help you out. <?php $myname = "Noxin"; echo "<p>This is PHP</p>"; echo "<p>My name is $myname</p>"; echo "<p>My name in another notation is still " . $myname . "</p>"; ?> If you're not the type to echo out everything, then I guess you can do a whole line just like Notion mentioned. Always end your echos with a semicolon or you'll always receive an error. Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/#findComment-1499264 Share on other sites More sharing options...
Ch0cu3r Posted December 11, 2014 Share Posted December 11, 2014 @Noxin the original code you posted in line 1 was fine the problem was with the word and on line 3. All you needed to was remove that word and this would of solved the error. and is a logical operator they should only be in control structures, ie when comparing values Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/#findComment-1499274 Share on other sites More sharing options...
Noxin Posted December 11, 2014 Author Share Posted December 11, 2014 @Noxin the original code you posted in line 1 was fine the problem was with the word and on line 3. All you needed to was remove that word and this would of solved the error. and is a logical operator they should only be in control structures, ie when comparing values ok did just that still got a error on line 7 code stands at: <?php $myname = 'Noxin'; echo '<p>This is PHP</p>'; echo "<p>My name is $myname</p>" echo '<p>My name in another notation is still '.$myname.'</p>'; ?> ERROR is Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';' in C:\Users\RoSeAnN\Desktop\Web Designing\server\htdocs\Practice.php on line 7 Do I just delete the echo??? Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/#findComment-1499290 Share on other sites More sharing options...
Ch0cu3r Posted December 11, 2014 Share Posted December 11, 2014 On line 6 add a semi-colon at the end of the line echo "<p>My name is $myname</p>"; Remember all statements must end with a semi-colon. Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/#findComment-1499291 Share on other sites More sharing options...
Noxin Posted December 11, 2014 Author Share Posted December 11, 2014 Good news is usually PHP provides more guidance regarding errors. Bad news is when you are just starting off, you will get a bunch of these. At first, try to keep your echo's small and don't mix single and double quotes. I always "just because" put parenthesis around the stuff I want to echo. Know that a semicolon is "mostly" end of command, and keep an eye out for them. Use a dot (.) to join stuff. <?php $myname = 'Noxin'; echo '<p>This is PHP</p>'. "<p>My name is $myname</p>". '<p>My name in another notation is still '.$myname.'</p>'; ?> PS. See http://php.net/manual/en/language.types.string.php Also, I would probably use the following even though the curly brackets are not required: echo("<p>This is PHP</p><p>My name is {$myname}</p><p>My name in another notation is still {$myname}</p>"); Thanks for this line of code but what made this work??? Its nice to know that php and mysql are working as they should on my system I think this Forum should make some newbie challenges that are easy to solve for you pro's, But challenging for beginners. The stuff on the web in just un-accurate and with no one there to help you figure the problems out its near impossible to get your head around. Thank you for this problem solve Im going to sit and compare the two codes now and try to understand where I went wrong. Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/#findComment-1499293 Share on other sites More sharing options...
cyberRobot Posted December 11, 2014 Share Posted December 11, 2014 Know that a semicolon is "mostly" end of command, and keep an eye out for them. Use a dot (.) to join stuff. <?php $myname = 'Noxin'; echo '<p>This is PHP</p>'. "<p>My name is $myname</p>". '<p>My name in another notation is still '.$myname.'</p>'; ?> While the above code should work, I would recommend using some caution. It's too easy to miss that concatenation character at the end and add a new statement where it shouldn't be. There have been a number of posts to this forum where something like the following doesn't work: <?php $myname = 'Noxin'; echo '<p>This is PHP</p>'. echo '<p>Just adding a new line that needs to go here</p>'; "<p>My name is $myname</p>". '<p>My name in another notation is still '.$myname.'</p>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/#findComment-1499298 Share on other sites More sharing options...
cyberRobot Posted December 11, 2014 Share Posted December 11, 2014 Thanks for this line of code but what made this work??? Did you see Ch0cu3r reply? It should fix your code. The following should work (note the semi-colon after the second echo): <?php $myname = 'Noxin'; echo '<p>This is PHP</p>'; echo "<p>My name is $myname</p>"; echo "<p>My name in another notation is still $myname</p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/#findComment-1499301 Share on other sites More sharing options...
mac_gyver Posted December 11, 2014 Share Posted December 11, 2014 I think this Forum should make some newbie challenges that are easy to solve for you pro's, But challenging for beginners. the problems you are having in this thread are all syntax errors, i.e. grammar, punctuation, spelling... errors. they are not actually programming problems yet, because your code didn't get past the first step php takes of parsing (similar to proofreading) the code to see if it can understand what you wrote and can run it. learning a programming language is pretty much the same as learning a linguistic language, except there are actually fewer rules to learn for a programming language and a programming language must be exact, where as there can be slight errors in the usage of a linguistic language and it can still be understood. when learning a linguistic language, you must first learn and practice the basic grammar, punctuation, spelling,.. before you can hope to be understood by someone else using that language. the same is true of php. you must first learn and practice the basic grammar, punctuation, spelling,.. of the php language before php can understand and run the code you have written. the reason programming help forums don't have sections showing the basic grammar, punctuation, spelling,.. used by php is because these things are already completely covered in the php.net documentation, which is the defining source of all the php language information. Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/#findComment-1499312 Share on other sites More sharing options...
Tom8001 Posted December 11, 2014 Share Posted December 11, 2014 I was reading how to do some beginner stuff in PHP so this to you guys is easy right? Why dosent the code work properly? And or am I trying stuff that is to advanced for a total noob?? this is the php code from the tutorial: <?php $myname = 'Noxin'; and echo '<p>This is PHP</p>'; echo "<p>My name is $myname</p>" echo '<p>My name in another notation is still '.$myname.'</p>'; ?> This is what appears on my localhost: Parse error: syntax error, unexpected 'and' (T_LOGICAL_AND) in C:\Users\RoSeAnN\Desktop\Web Designing\server\htdocs\Practice.php on line 3 Your second echo statement does not have a semi colon echo "<p>My name is $myname</p>" $myname = 'Noxin'; ^ put "Noxin" you are only storing text in the variable so it must be a string Also you put and for no reason that will not do anything. I think what you were trying to do is: <?php $myname = "Noxin"; echo "<p>This is PHP</p>"; echo "<p>My name is $myname</p>"; echo "<p>My name in another notation is still ".$myname." "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/#findComment-1499339 Share on other sites More sharing options...
Noxin Posted December 12, 2014 Author Share Posted December 12, 2014 (edited) Did you see Ch0cu3r reply? It should fix your code. The following should work (note the semi-colon after the second echo): Yes I did. It solved the problem eventually.How ever reading a piece of code that worked straight away was much more helpfull,Because of that help I have moved on today a lot and now understand PHP better. But thank you to everyone who posted it has all helped!! I'm sure I'm going to be back with some more noob stuff soon. Edited December 12, 2014 by Noxin Quote Link to comment https://forums.phpfreaks.com/topic/293021-cant-even-get-basics-right/#findComment-1499386 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.