![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 60 Pomógł: 0 Dołączył: 14.09.2012 Ostrzeżenie: (0%) ![]() ![]() |
Mam problem ze skłądnią heredoc. Po wpisaniu takiego kodu:
$message = <<< EOT <p>Wpisz swój adres email</p> <form method = "post" action="$file "> <input type="text" sixe=25 name="email"> <br> <input type="submit" name="submit" value="Zapisz"> </form> EOT; Składnia nie kończy się. Cały kod, który znajduje się poniżej zapisany jest do $message. Co jest nie tak? |
|
|
![]() |
![]()
Post
#2
|
|
Grupa: Zarejestrowani Postów: 590 Pomógł: 107 Dołączył: 25.10.2011 Ostrzeżenie: (0%) ![]() ![]() |
spacja pomiędzy "<<<" a "EOT" w pierwszej linii (IMG:style_emoticons/default/smile.gif)
|
|
|
![]()
Post
#3
|
|
Grupa: Zarejestrowani Postów: 60 Pomógł: 0 Dołączył: 14.09.2012 Ostrzeżenie: (0%) ![]() ![]() |
No właśnie chyba nie. O dziwo w jednym miejscu składnia mi działa wtedy, gdy jest bezpośrednio w kodzie php, a w innym miejscu w funkcji if zapisuje mi do zmiennej cały kod poniżej.
|
|
|
![]()
Post
#4
|
|
Grupa: Zarejestrowani Postów: 590 Pomógł: 107 Dołączył: 25.10.2011 Ostrzeżenie: (0%) ![]() ![]() |
Pokaż kod z obu przypadków.
|
|
|
![]()
Post
#5
|
|
Grupa: Zarejestrowani Postów: 60 Pomógł: 0 Dołączył: 14.09.2012 Ostrzeżenie: (0%) ![]() ![]() |
Tutaj do heredoc wciąga cały kod od <<< EOT:
<?php if($_POST['submit'] == "Zapisz"){ if(!$_POST['email'] || $_POST['email'] || strlen($_POST['email'] > 30)){ $message = "<p>Błąd. Czy na pewno podałeś adres email?</p>"; }else{ mysql_connect('localhost', 'root', '7war') or die("błąd połączenia z bazą danych"); mysql_select_db('email'); $as_email = addcslashes($_POST['email']); $trim_email = trim($as_email); $query = "INSERT INTO adresy (id, email, source) VALUES (NULL, '$trim_email', 'www.przyklad.com')"; $result = mysql_query($query); if(mysql_affected_rows() == 1){ $message = "<p>Adres został zapisany</p>"; $noform_var = 1; }else{ $message = "<p>Próba zapisania adresu nie powiodła się</p>"; } } } if(!$noform_var){ $thisfile = $_SERVER['PHP_SELF']; $message = <<< EOT <p>Wpisz swój adres email</p> <form method = "post" action=" "> <input type="text" sixe=25 name="email"> <br> <input type="submit" name="submit" value="Zapisz"> </form> EOT; } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Mysql2</title> </head> <body> <table border="0" cellpadding="10" width="100%"> <tr><td bgcolor="#F0F8FF" align="center" valign="top" width="17%"></td><td bgcolor="#FFFFFF" align="left" valign="top" width="83%"><h1>Formularz zapisu na listę wysyłkową</h1><?php echo $message ?></td></tr> </table> </body> </html> A tutaj wszystko jest jak być powinno: <?php $thisfile = $_SERVER['PHP_SELF']; $reg_form = <<< EOREGFORM <p>Musisz podać swoje imie nazwisko i meail, by zagwarantować, że nikt nie zagłosuje więcej niż jeden raz. Dene te nie zostaną jendak połączone z ankietą</p> <form method="post" action="$thisfile"> imie i nazwisko: <input type="text" size="25" name="name"> <br><br> email: <input type="text" size="25" name="email"> <input type="hidden" name="stage" value="register"> <br><br> <input type="submit" name="submit" value="Zapisz"> EOREGFORM; $rate_form = <<< EORATEFORM <p>Mój szef: </p> <form method="post" action="$thisfile"> <input type="radio" name="rating" value="1">zły <input type="radio" name="rating" value="2">może być <input type="radio" name="rating" value="3">dobry imie i nazwisko szefa: <input type="text" size="25" name="boss"> <input type="hidden" name="stage" value="rate"> <br><br> <input type="submit" name="submit" value="Zapisz"> </form> EORATEFORM; if(!$_POST['submit']){ $message=$reg_form; }elseif($_POST['submit'] == 'Zapisz' && $_POST['stage'] == 'register'){ if(!$_POST['name'] || $_POST['name'] == "" || strlen($_POST['name'] > 30)){ $message = "wystąpił problem, czy na pewno wpisałeś adres email?"; $message = $reg_form; }else{ mysql_connect('localhost', 'root', '7war'); mysql_select_db('email'); $as_email = addslashes($_POST['email']); $trim_email = trim($as_email); $as_name = addslashes($_POST['name']); $trim_name = trim($as_name); $query="select id from adres where name='$trim_name AND email='$trim_email' "; $result = mysql_query($query); if(mysql_num_rows($result) > 0){ $message = "ktoś o takim imieniu oraz adresie email już wypełniał formularz"; }else{ $query = "insert into adres (id, email, source, name) values ('null', '$trim_email' , 'null' , '$trim_name')"; $result = mysql_query($query); if(mysql_affected_rows($result)==1){ $message = "dodano ankiete"; }else{ $message = "Nie powiodło się"; } } } }elseif($_POST['submit'] == 'Zapisz' && $_POST['stage'] == 'rate'){ mysql_connect('localhost', 'root', '7war'); mysql_select_db('email'); $as_boss = addslashes($_POST['boss']); $trim_boss = trim($_POST['boss']); $rating = $_POST['rating']; $query = "INSERT INTO ratings (id, rating, boss) VALUES (NULL, '$rating', '$trim_boss)"; $result = mysql_query($query); if(mysql_affected_rows($result) == 1){ $message = "Twoja ankieta została zapisana"; }else { error_log(mysql_error()); $message = "<p>Proba nie powiodła się spróbuj jeszcze raz</p>"; $message = $rate_form; } } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Mysql2</title> </head> <body> <table border="0" cellpadding="10" width="100%"> <tr><td bgcolor="#F0F8FF" align="center" valign="top" width="17%"></td><td bgcolor="#FFFFFF" align="left" valign="top" width="83%"><h1>Anonimowo oceń swojego szefa</h1><?php echo $message ?></td></tr> </table> </body> </html> |
|
|
![]() ![]() |
![]() |
Aktualny czas: 24.08.2025 - 20:40 |