Jump to content

<P> tag within PHP to output PHP var?

Flanelman
Go to solution Solved by Syntaxvgm,

what you're missing is concatenation. Also, extra semicolon

 

Now, I'm really tired, so I may written this down wrong, but something like this

 echo '<p class="added_text"> Sailor' $first $last ' added Successfully to team ' $team '  </p>;';

should be 

 echo '<p class="added_text"> Sailor' . $first . $last .' added Successfully to team '. $team .'  </p>';

 

 

edit

see forgot a period. Done goofed, hope it's right now. I could be way off. 

Hey guys, so I imagine this is pretty easy I just can't seem to figure it out.

So, I'm trying to pretty much print out "Sailor <FirstName> <LastName> has been added!" where <FirstName> and <LastName> are PHP post variables.

Here's what I've tried:

 

- Post Vars

     $first = $_POST['first'];
     $last = $_POST['last'];
     $gender = $_POST['gender'];
     $country = $_POST['country'];
     $team = $_POST['team'];
     $position = $_POST['position'];

- Within PHP
          echo '<p class="added_text"> Sailor' $first $last ' added Successfully to team ' $team '  </p>;';
- Outside PHP
          <p class="added_message"> Sailor <?php $first $last ?> added Successfully to team <?php $team ?> </p>;

 

Both just seem to give me "unexpected $first" error, however, I know the data is there as I can print_R($_POST) and all the data is there so I'm guessing I'm just making a mistake.

Any help would be greatly appreciated. :) Thanks!

Link to comment
Share on other sites

Link to post
Share on other sites

what you're missing is concatenation. Also, extra semicolon

 

Now, I'm really tired, so I may written this down wrong, but something like this

 echo '<p class="added_text"> Sailor' $first $last ' added Successfully to team ' $team '  </p>;';

should be 

 echo '<p class="added_text"> Sailor' . $first . $last .' added Successfully to team '. $team .'  </p>';

 

 

edit

see forgot a period. Done goofed, hope it's right now. I could be way off. 

muh specs 

Gaming and HTPC (reparations)- ASUS 1080, MSI X99A SLI Plus, 5820k- 4.5GHz @ 1.25v, asetek based 360mm AIO, RM 1000x, 16GB memory, 750D with front USB 2.0 replaced with 3.0  ports, 2 250GB 850 EVOs in Raid 0 (why not, only has games on it), some hard drives

Screens- Acer preditor XB241H (1080p, 144Hz Gsync), LG 1080p ultrawide, (all mounted) directly wired to TV in other room

Stuff- k70 with reds, steel series rival, g13, full desk covering mouse mat

All parts black

Workstation(desk)- 3770k, 970 reference, 16GB of some crucial memory, a motherboard of some kind I don't remember, Micomsoft SC-512N1-L/DVI, CM Storm Trooper (It's got a handle, can you handle that?), 240mm Asetek based AIO, Crucial M550 256GB (upgrade soon), some hard drives, disc drives, and hot swap bays

Screens- 3  ASUS VN248H-P IPS 1080p screens mounted on a stand, some old tv on the wall above it. 

Stuff- Epicgear defiant (solderless swappable switches), g600, moutned mic and other stuff. 

Laptop docking area- 2 1440p korean monitors mounted, one AHVA matte, one samsung PLS gloss (very annoying, yes). Trashy Razer blackwidow chroma...I mean like the J key doesn't click anymore. I got a model M i use on it to, but its time for a new keyboard. Some edgy Utechsmart mouse similar to g600. Hooked to laptop dock for both of my dell precision laptops. (not only docking area)

Shelf- i7-2600 non-k (has vt-d), 380t, some ASUS sandy itx board, intel quad nic. Currently hosts shared files, setting up as pfsense box in VM. Also acts as spare gaming PC with a 580 or whatever someone brings. Hooked into laptop dock area via usb switch

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, Syntaxvgm said:

what you're missing is concatenation. Also, extra semicolon

 

Now, I'm really tired, so I may written this down wrong, but something like this


 echo '<p class="added_text"> Sailor' $first $last ' added Successfully to team ' $team '  </p>;';

should be 


 echo '<p class="added_text"> Sailor' . $first $last .' added Successfully to team '. $team .'  </p>';

 

Ah that was the problem, needed a period before $last too but that was the issue, thanks heaps man! :D

here's the code that I used:
echo '<p class="added_text"> Sailor ' . $first .' ' .$last .' added Successfully to team '. $team .'  </p>';

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, Flanelman said:

Ah that was the problem, needed a period before $last too but that was the issue, thanks heaps man! :D

here's the code that I used:
echo '<p class="added_text"> Sailor ' . $first .' ' .$last .' added Successfully to team '. $team .'  </p>';

yah I saw that, I corrected it but too late. 

Also the other way needed an echo still. 

  <p class="added_message"> Sailor <?php $first $last ?> added Successfully to team <?php $team ?> </p>;

Should be 

  <p class="added_message"> Sailor <?php echo $first . $last ?> added Successfully to team <?php echo $team ?> </p>;

If you are running php 5.4 or above, or have short_open_tag enabled, you can do this I think 
 <p class="added_message"> Sailor <?= $first . $last ?> added Successfully to team <?= $team ?> </p>;
Where the opening tag is now just <? and <?= for echo 

I probably fucked this one up too.  

muh specs 

Gaming and HTPC (reparations)- ASUS 1080, MSI X99A SLI Plus, 5820k- 4.5GHz @ 1.25v, asetek based 360mm AIO, RM 1000x, 16GB memory, 750D with front USB 2.0 replaced with 3.0  ports, 2 250GB 850 EVOs in Raid 0 (why not, only has games on it), some hard drives

Screens- Acer preditor XB241H (1080p, 144Hz Gsync), LG 1080p ultrawide, (all mounted) directly wired to TV in other room

Stuff- k70 with reds, steel series rival, g13, full desk covering mouse mat

All parts black

Workstation(desk)- 3770k, 970 reference, 16GB of some crucial memory, a motherboard of some kind I don't remember, Micomsoft SC-512N1-L/DVI, CM Storm Trooper (It's got a handle, can you handle that?), 240mm Asetek based AIO, Crucial M550 256GB (upgrade soon), some hard drives, disc drives, and hot swap bays

Screens- 3  ASUS VN248H-P IPS 1080p screens mounted on a stand, some old tv on the wall above it. 

Stuff- Epicgear defiant (solderless swappable switches), g600, moutned mic and other stuff. 

Laptop docking area- 2 1440p korean monitors mounted, one AHVA matte, one samsung PLS gloss (very annoying, yes). Trashy Razer blackwidow chroma...I mean like the J key doesn't click anymore. I got a model M i use on it to, but its time for a new keyboard. Some edgy Utechsmart mouse similar to g600. Hooked to laptop dock for both of my dell precision laptops. (not only docking area)

Shelf- i7-2600 non-k (has vt-d), 380t, some ASUS sandy itx board, intel quad nic. Currently hosts shared files, setting up as pfsense box in VM. Also acts as spare gaming PC with a 580 or whatever someone brings. Hooked into laptop dock area via usb switch

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Syntaxvgm said:

yah I saw that, I corrected it but too late. 

Also the other way needed an echo still. 


  <p class="added_message"> Sailor <?php $first $last ?> added Successfully to team <?php $team ?> </p>;

Should be 

  <p class="added_message"> Sailor <?php echo $first . $last ?> added Successfully to team <?php echo $team ?> </p>;

If oyu are running php 5.4 or above, or have short_open_tag enabled, you can do this I think 
 <p class="added_message"> Sailor <?= $first . $last ?> added Successfully to team <?= $team ?> </p>;
Where the opening tag is now just <? and <?= for echo 

I probably fucked this one up too.  

Haha well I appreciate the help none the less! Thanks again dude. :)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×