Jump to content

Cant even get basics right :/


Noxin

Recommended Posts

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
 
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by NotionCommotion
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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???
Link to comment
Share on other sites

 

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. :)

Link to comment
Share on other sites

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>';
?>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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."  ";
?>
Link to comment
Share on other sites

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 by Noxin
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.