rubyarat2010 Posted July 9, 2012 Share Posted July 9, 2012 This gives me errors I cant make it one line how can i make multilin? $content = ' <!doctype html> <html> <head> <title>Zen Davis.com</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="style.css" type="text/css" rel="stylesheet" /> </head> <body link="#5e6959" h3="#5e6959" vlink="#5e6959" > <div class="content"> <div class="top_block NavMenu"> <div class="content"> <!--Navigation line --> <h1 style="text-align:center" ><p><a href="index.php" style="text-decoration: none" >Home</a>  <a href="About.html" style="text-decoration: none" >About</a>   <a href="Contact.php" style="text-decoration: none" >Contact</a>   <a href="Games.php" style="text-decoration: none" size="25">Games</a></p></h1> </div> </div> <div class="top_block MiddlePhoto"> <div class="content" style="text-align:center"> Author: $author <br/> Date: $date <br/> $body </div> </div> </div> <div class="top_block BottomTables"> <div class="content"> </div> </div> </div> </body> </html> '; Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/ Share on other sites More sharing options...
Psycho Posted July 9, 2012 Share Posted July 9, 2012 You need to state what error you are getting. I see nothing in that which would cause an error - but I'm positive it won't produce the results you are wanting. You open the string with a single quote and close it with a single quote. Plus, there are no single quotes inside the string (if there were they would just need to be escaped). So, the string is properly defined. However inside the string I see what I assume are PHP variables: Date: $date <br/> PHP variables are not interpreted inside single quoted strings, but they are within double quoted strings (there are also the nowdoc and heredoc methods of defining strings that work the same, respectively). You should read this page: http://php.net/manual/en/language.types.string.php especially the section about variable parsing: http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing So, you can do a few different things: 1. Continue defining the string using single quotes. You would need to close/reopen the sting to append the variables such as: $var = 'Date: ' . $date . '<br>'; 2. Change the string to be defined by double quotes and do one of the following: a. Escape all instances of double quotes inside the string <div class=\"content\"> b. Change all instances of double quotes to single quotes inside the string <div class='content'> Many times you cannot do just a or just b, but have to use a combination of both. For example, if you were trying to display a measurement of 4 feet, 5 inches it should be displayed as follows: 4'5". So, you would have to escape which ever one was used to define the string. You can even mix and match different quotes for different parts of the strings. But, I think it's better to stick to one style - at least until you really understand it all and know why one method is better than another for a specific situation. Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360294 Share on other sites More sharing options...
rubyarat2010 Posted July 9, 2012 Author Share Posted July 9, 2012 Parse error: syntax error, unexpected T_VARIABLE in /home/zendavis/public_html/insert.php on line 19 Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360320 Share on other sites More sharing options...
rubyarat2010 Posted July 9, 2012 Author Share Posted July 9, 2012 <?php $author=$_POST["author"]; $date=$_POST["date"]; $title=$_POST["title"]; $body=$_POST["body"]; $imagelink=$_POST["imgl"]; $con = mysql_connect("localhost","zendavis_tim","######"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("zendavis_posts", $con); mysql_query("INSERT INTO posts1 (author, imagelink,date,body,title) VALUES ('$author', '$imagelink','$date','$body','$title')"); $title = str_replace(" ", "_", $title) $content = ' <!doctype html> <html> <head> <title>Zen Davis.com</title> <meta http-equiv=\"Content-Type"\ content=\"text/html; charset=utf-8" \/> <link href=\"style.css"\ type=\"text/css"\ rel=\"stylesheet"\ /> </head> <body link=\"#5e6959"\ h3=\"#5e6959"\ vlink=\"#5e6959"\ > <div class=\"content"\> <div class=\"top_block NavMenu"\> <div class=\"content"\> <!--Navigation line --> <h1 style=\"text-align:center"\ ><p><a href=\"index.php"\ style=\"text-decoration: none"\ >Home</a>  <a href=\"About.html"\ style=\"text-decoration: none"\ >About</a>   <a href=\"Contact.php"\ style=\"text-decoration: none"\ >Contact</a>   <a href=\"Games.php"\ style=\"text-decoration: none"\ size=\25"\>Games</a></p></h1> </div> </div> <div class=\"top_block MiddlePhoto"\> <div class=\"content"\ style=\"text-align:center"\> Author: '$author' <br/> Date: '$date' <br/> '$body' </div> </div> </div> <div class=\"top_block BottomTables"\> <div class=\"content"\> </div> </div> </div> </body> </html> '; $file = "$title.html"; $open = fopen($file, "w"); fwrite($open, $content); fclose($open); header("Location: http://zendavis.com/$title.html"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360321 Share on other sites More sharing options...
mikosiko Posted July 9, 2012 Share Posted July 9, 2012 ..... mysql_query("INSERT INTO posts1 (author, imagelink,date,body,title) VALUES ('$author', '$imagelink','$date','$body','$title')"); $title = str_replace(" ", "_", $title) /// YOU ARE MISSING A ; HERE $content = ...... Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360342 Share on other sites More sharing options...
rubyarat2010 Posted July 9, 2012 Author Share Posted July 9, 2012 but thats not in the html? Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360348 Share on other sites More sharing options...
mikosiko Posted July 9, 2012 Share Posted July 9, 2012 fix that and follow Psycho recommendations Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360350 Share on other sites More sharing options...
rubyarat2010 Posted July 9, 2012 Author Share Posted July 9, 2012 mikosiko works now but now the php variables in the html dont work? Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360352 Share on other sites More sharing options...
rubyarat2010 Posted July 9, 2012 Author Share Posted July 9, 2012 mikosiko works now but now the php variables in the html dont work? Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360354 Share on other sites More sharing options...
xyph Posted July 9, 2012 Share Posted July 9, 2012 Strings surrounded by single quotes won't evaluate variables within them. You need double quotes, and you need to RTFM. http://php.net/manual/en/language.types.string.php They go into huge detail, and provide many examples. Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360355 Share on other sites More sharing options...
Psycho Posted July 9, 2012 Share Posted July 9, 2012 but thats not in the html? Because the error you received had nothing to do with the multi-line HTML string variable! The error told you what line the error was on. Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360366 Share on other sites More sharing options...
rubyarat2010 Posted July 9, 2012 Author Share Posted July 9, 2012 sorry but this didint work Author: "$author" <br/> Date: " $date" <br/> "$body" Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360375 Share on other sites More sharing options...
rubyarat2010 Posted July 9, 2012 Author Share Posted July 9, 2012 <?php echo $author ?> this didint work either. Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360376 Share on other sites More sharing options...
jcbones Posted July 9, 2012 Share Posted July 9, 2012 Psycho went into great detail in his first reply. Please don't waste that post, as the info is very accurate. Follow the first example, marked by 1.(one), and it will work. Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360378 Share on other sites More sharing options...
rubyarat2010 Posted July 9, 2012 Author Share Posted July 9, 2012 Still Gives me erorrs:(((((( <?php $author=$_POST["author"]; $date=$_POST["date"]; $title=$_POST["title"]; $body=$_POST["body"]; $imagelink=$_POST["imgl"]; $link = $title ; $con = mysql_connect("localhost","zendavis_tim","sherlock11<>"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("zendavis_posts", $con); mysql_query("INSERT INTO posts1 (author, imagelink,date,body,title,link) VALUES ('$author', '$imagelink','$date','$body','$title','$link')"); $title = str_replace(" ", "_", $title); $conatent = ' <!doctype html> <html> <head> <title>Zen Davis.com</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="style.css" type="text/css" rel="stylesheet" /> </head> <body link="#5e6959" h3="#5e6959" vlink="#5e6959" > <div class="content"> <div class="top_block NavMenu"> <div class="content"> <!--Navigation line --> <h1><div style="text-align:center"><p><a href="Index.php" style="text-decoration: none" >Home</a>  <a href="About.html" style="text-decoration: none" >About</a>   <a href="Contact.php" style="text-decoration: none" >Contact</a>   <a href="Games.php" style="text-decoration: none" size="25">Games</a></p></div></h1> </div> </div> <div class="top_block MiddlePhoto"> <div class="content"> Author:'$author; '<br/> Date: '$date;' <br/> ' $body;' </div> </div> <div class="top_block BottomTables"> <div class="content"> </div> </div> </div> <!-- * Layout generated with http://layzilla.com * Layout generator is free of use. * We appreciate if you leave this comment block in commercial use of generator. * All comment and ideas can be submitted to us using contacts below. * * site: www.jmholding.com * email: info@jmholding.ru * twitter: @jmholding --> </body> </html> '; $file = "$title.html"; $open = fopen($file, "w"); fwrite($open, $conatent); fclose($open); header("Location: http://zendavis.com/$link.html"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360393 Share on other sites More sharing options...
mikosiko Posted July 9, 2012 Share Posted July 9, 2012 ..... PHP variables are not interpreted inside single quoted strings, but they are within double quoted strings (there are also the nowdoc and heredoc methods of defining strings that work the same, respectively)........ So, you can do a few different things: 1. Continue defining the string using single quotes. You would need to close/reopen the sting to append the variables such as: $var = 'Date: ' . $date . '<br>'; ...... What part of # 1 you didn't understood?... are you even paying attention to what the people trying to helping you had wrote for you?... doesn't look like. Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360401 Share on other sites More sharing options...
rubyarat2010 Posted July 9, 2012 Author Share Posted July 9, 2012 I did even tried puting periods like he showed Author:'$author; '<br/> Date: '$date;' <br/> ' $body;' Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360413 Share on other sites More sharing options...
Adam Posted July 9, 2012 Share Posted July 9, 2012 There's not a single period (".") in that bit of code you just posted? Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360416 Share on other sites More sharing options...
rubyarat2010 Posted July 10, 2012 Author Share Posted July 10, 2012 Ok i got it one other thing i assighn the header at the end but it gives me this error Warning: Cannot modify header information - headers already sent by (output started at /home/zendavis/public_html/insert.php:2) in /home/zendavis/public_html/insert.php on line 76? Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360443 Share on other sites More sharing options...
jcbones Posted July 10, 2012 Share Posted July 10, 2012 Did you read the manual for header? I ask because the second line under the function description is: Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file. Quote Link to comment https://forums.phpfreaks.com/topic/265431-multiline-variable/#findComment-1360461 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.