J0E Posted January 30, 2012 Share Posted January 30, 2012 Hi there, I was trying to modify the code from the tutorial "PHP Basic Database Handling" and the code uses something I haven't seen before, but looks intriguing. Can someone explain how to use this: echo <<<SOMELABEL stuff SOMELABEL; Or let me know why my code didn't work? The error is an unexpected end statement on the last line of the file. My Code: <?php $mystring = $_GET['FirstLast']; if($mystring == "") { echo "You reached this page by mistake, click on the link in your email"; }else { //echo $mystring; // connect to db $conn = mysql_connect('localhost','user','pw') or trigger_error("SQL",E_USER_ERROR); $db = mysql_select_db('tsec',$conn) or trigger_error("SQL",E_USER_ERROR); $sql = "SELECT `First Name`, `Last Name`, `Title`, `Org Parameter 1`, `Org/Person Name`, `Attendee Parm Value 1`, `Attendee Parm Value 2`, `Attendee Parm Value 3`, `Attendee Parm Value 4`, `Attendee Parm Value 5`, `Attendee Parm Value 6`, `Attendee Parm Value 7`, `Attendee Parm Value 8` FROM `attendees` WHERE FirstLast = '$mystring'"; $result = mysql_query($sql,$conn) or trigger_error("SQL", E_USER_ERROR); $list = mysql_fetch_assoc($result); echo <<<LISTNAME <form action = '{$_SERVER['PHP_SELF']}' method = 'post'> <table border = '1'><tr><td colspan = '2'>{$list['First Name']} {$list['Last Name']}</td></tr> <tr><td>Title</td><td><input type = 'text' name = 'Title' value = {$list['Title']}</td></tr> </table></form> LISTNAME; mysql_close($conn); } ?> Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/256066-syntax-help/ Share on other sites More sharing options...
Pikachu2000 Posted January 30, 2012 Share Posted January 30, 2012 That's called HEREDOC syntax. The explanation can be found here: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc Quote Link to comment https://forums.phpfreaks.com/topic/256066-syntax-help/#findComment-1312713 Share on other sites More sharing options...
AyKay47 Posted January 30, 2012 Share Posted January 30, 2012 from the manual: Warning It is very important to note that the line with the closing identifier must contain no other characters, except possibly a semicolon (. That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter (possibly followed by a semicolon) must also be followed by a newline. you have tabbed your closing identifier. Quote Link to comment https://forums.phpfreaks.com/topic/256066-syntax-help/#findComment-1312715 Share on other sites More sharing options...
J0E Posted January 30, 2012 Author Share Posted January 30, 2012 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/256066-syntax-help/#findComment-1312721 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.