NickkN
NickkN

Reputation: 29

data not being published: unexpected T_STRING

I'm having trouble with the way I'm doing it, I've tried some different ways but nothing seems to work.

When I have it like the code below, it works but it doesn't insert the username data.

I get the error page with message "Parse error: syntax error, unexpected T_STRING"

<?php

include "connect.php"; //connection string

print "<link rel='stylesheet' href='style.css' type='text/css'>";

print "<table class='maintables'>";

print "<tr class='headline'><td>Post a message</td></tr>";

print "<tr class='maintables'><td>";

if(isset($_POST['submit']))

{

   $name=$_POST['name'];

   $yourpost=$_POST['yourpost'];

   $subject=$_POST['subject'];

   if(strlen($name)<1)

   {

      print "You did not type in a name."; //no name entered

   }

   else if(strlen($yourpost)<1)

   {

      print "You did not type in a post."; //no post entered

   }

   else if(strlen($subject)<1)

   {

      print "You did not enter a subject."; //no subject entered

   }

   else

   {

      $thedate=date("U"); //get unix timestamp

      $displaytime=date("F j, Y, g:i a");

      //we now strip HTML injections

      $subject=strip_tags($subject);

      $name=strip_tags($name);

      $yourpost=strip_tags($yourpost); 

      $insertpost="INSERT INTO forumtutorial_posts(author,title,post,showtime,realtime,lastposter) values('$name','$subject','$yourpost','$displaytime','$thedate','$name')";

      mysql_query($insertpost) or die("Could not insert post"); //insert post

      print "Message posted, go back to <A href='index.php'>Forum</a>.";

   }



}

else

{

   print "<form action='post.php' method='post'>";

   print "<input type='hidden' name='name' value='<? echo("$_SESSION[usr_name]");?>' size='20'><br>";

   print "Subject:<br>";

   print "<input type='text' name='subject' size='20'><br>";

   print "Your message:<br>";

   print "<textarea name='yourpost' rows='5' cols='40'></textarea><br>";

   print "<input type='submit' name='submit' value='submit'></form>";



}

print "</td></tr></table>";

?>

If I make it so that users put the username as they desire, it works but I want it to work like the code above with our system session.

Is there another way around? thanks!

Upvotes: 0

Views: 230

Answers (1)

Tadeck
Tadeck

Reputation: 137380

Problem

You provided not many details, but I see at least one syntax error here:

print "<input type='hidden' name='name' value='<? echo("$_SESSION[usr_name]");?>' size='20'><br>";

You just lack valid characters between string and variable:

print "<input (...) echo("$_SESSION[usr_name]"); (...)";
                         ^^                 ^^

But trying to guess what you wanted, I bet you basically include PHP code within string, within PHP code, and you do it incorrectly.

Solution

Do this like that instead:

print "<input type='hidden' name='name' value='$_SESSION[usr_name]' size='20'><br>";

or even cleaner:

print '<input type="hidden" name="name" value="' . $_SESSION[usr_name] . '" size="20"><br>';

Upvotes: 1

Related Questions