使用 php 未在页面上打印 Echo

发布于 2024-11-24 16:40:29 字数 8028 浏览 5 评论 0原文

我正在尝试使用 php 创建一个网页。问题是有时我会遇到服务器错误,有时我却得不到任何回报。在某一时刻,服务器本身更改了文件类型。我不知道问题是什么。

因为我实际上不知道问题是什么,所以我将整个文件粘贴到这里,即使我预计问题是前几行(我把它放在这里: http://www.iandapp.com/smic/subscription.php) :

<?php header('Content-Type: text/html; charset=ISO-8859-1');

echo("<div id='subscribe'>");

$mail = $_POST['email1'];

//Set the locale format, etc. of date and time
date_default_timezone_set('Europe/Stockholm');
setlocale(LC_TIME, "sv_SV");

//Create the db-connection
$mysqli = mysqli_connect("mydb", "myuser", "mupsw", "myschema", "3306");

//If verifying the subscription, makse sure the db is updated accordingly
if($_GET['newid'] != ""){
    //Make the subscriber a verified subscriber
    $result = mysqli_query($mysqli,"UPDATE users SET subscriber = 1 WHERE id = " . $_GET['newid']);
    if($result){
        echo("<p>Welcome to our newsletter! We will send you information about any new application or update. This will not happen too often, but once it does we hope you will have the opportunity to look into our site again.<p/>");
        echo("<p><br/>If you wish to unsubscribe from this mail-list, please visit out subscription page: <a href="http://" . $_SERVER['HTTP_HOST'] . "/subscription.php"> http://" . $_SERVER['HTTP_HOST'] . "/subscription.php </a> <p/>");
    }else{
        echo("<p>Somthing went wrong, please click the link again!<p/>");
    }

}elseif($_POST['email1'] != ""){ //Only do things if there is an e-mail posted

    //Make sure the ID is unique
    do{
        $rand_int = rand(100000000, 999999999);
        $result = mysqli_query($mysqli, "SELECT id FROM users WHERE id = " . $rand_int);

        $no_of_rows = mysqli_num_rows($result);

        }while($no_of_rows != 0);
    echo("RAND :".$rand_int);

    //Create query for saving the new user e-mail
    $query = "INSERT INTO users(id, email, first_name, surname) VALUES ('" . $rand_int . "', '".$_POST['email1']."', '". $_POST['first_name']."','".$_POST['surname']."')";
    $re = mysqli_query($mysqli, $query);
    echo("Result: ".$re);

    //Check if mail already exist (Error code 1062 = dublicate entries for unique fields)
    $existing = 0;
    if(mysqli_errno($mysqli)==1062){
        echo("It seems like your e-mail already is registered. Perhaps you have been a subscriber earlier? By clicking the link that you will receive in your mail box you subscribe to the newsletter again. ");
        $existing = 1;
        $result = mysqli_query($mysqli,"SELECT id FROM users WHERE email = '" . $_POST['email1'] . "'");
        $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
        $rand_int = $row['id'];
        mysqli_query($mysqli,"UPDATE users SET waiting_for_unsubscribe = 0 WHERE email = '" . $_POST['email1'] . "'");
        if(mysqli_errno($mysqli)){
        echo("Error code " . mysqli_errno($mysqli) . "<br/>");
        echo("Error text " . mysqli_errno($mysqli) . "<br/>");
    }
        //echo("ID------ " . $row['id'] . " ri---- " . $rand_int);
    }



    //Create the link for the user to verify the subscription
    $url = "http://" . $_SERVER['HTTP_HOST'] . "/smic/subscription.php?newid=" . $rand_int;     


    $mymail = $_POST['email1'];
    $esubject = "Please verify your subscription to iAndApp's newsletter ";
    $body = "Click the link in order to verify your subscription (If you cannot click the link, just copy it and paste it into the adress field of your browser): " . $url;
    $eemail = "[email protected]";
    $sent = mail($mymail,$esubject,$body,"From: $eemailn");
    if($sent){
        if($existing != 1){
            echo "<br/>An e-mail with a link has been sent to ". $mymail . ". Please click the link in order to verify your subscription";
        }
    }else{
        echo "Something went wrong. Please try again and make sure you enter a correct e-mail adress.";
    }
    $existing = 0;

mysqli_free_result($result);

//If unsubscribing
}elseif($_POST['unsubscribedmail'] != ""){
    //echo("Unsubscribe........");
    //echo($_POST['unsubscribedmail']);
    $result = mysqli_query($mysqli,"UPDATE users SET waiting_for_unsubscribe = 1 WHERE email = '" . $_POST['unsubscribedmail'] . "'");

    //echo("Err code " . mysqli_errno($mysqli));
    //echo("Err text " . mysqli_error($mysqli));
    if(mysqli_errno($mysqli)){
        echo("Error code " . mysqli_errno($mysqli) . "<br/>");
        echo("Error text " . mysqli_errno($mysqli) . "<br/>");
    }

    $result = mysqli_query($mysqli,"SELECT id FROM users WHERE email = '" . $_POST['unsubscribedmail'] . "'");
    $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
    //echo("ID------ " . $row['id']);
    //Create the link for the user to verify that he/she  unsubscribes
    $url = "http://" . $_SERVER['HTTP_HOST'] . "/smic/subscription.php?unsubscribeid=" . $row['id'];

    $mymail = $_POST['unsubscribedmail'];
    $esubject = "Please verify that you want to unsubscribe from iAndApp's newsletter ";
    $body = "Click the link in order to verify that you want to unsubscribe from iAndApp's newsletter (If you cannot click the link, just copy it and paste it into the adress field of your browser): " . $url;
    $eemail = "[email protected]";
    $sent = mail($mymail,$esubject,$body,"From: $eemailn");
    if ($sent) echo "<br/>A mail with a link has been sent to ". $mymail . ". Please click the link in order to verify that you will unsubscribe from the newsletters.";
    else echo "Something went wrong. Please try again and make sure you enter a correct e-mail adress.";

mysqli_free_result($result);    
}elseif($_GET['unsubscribeid'] != ""){
    $result = mysqli_query($mysqli,"UPDATE users SET subscriber = 0, waiting_for_unsubscribe = 0 WHERE id = " . $_GET['unsubscribeid']);
    if($result){
        echo("<p>You have now unsubscribed to the newsletter. Thank you for this time and we hope to see you again in the future. /iAndApp.<p/>");
    }else{
        echo("<p>Somthing went wrong, please click the link again!<p/> ".$result);
    }

}else{

echo("<div class="subscribe">
<h4>Subscribe</h4>
<p>Subscribe to iAndApp's newsletter in order to get information about new and updated iPhone games and iPhone applications, that has been released by iAndApp. </p>
<form action="subscription.php" name="subscribe" method="post"  onsubmit="return isValidEmailAndEqual()">
<p class="formlabel">Förnamn</p> <input type="text" name="first_name"/><br/>
    <p class="formlabel">Efternamn</p> <input type="text" name="surname"/> <br/>
<p class="formlabel">E-mail</p> <input type="text" name="email1"/>
<br/>
<p class="formlabel">Repeat e-mail</p> <input type="text" name="email2"/> <br/>
<input class="inputsubmit" type="submit" value="Subscribe"/>
</form>
</div>");

echo("<div class="footer"></div>");


echo("<div class="subscribe">
<h4>Unsubscribe</h4>
<p>Fill in your e-mail address and submit in order to unsubscribe from iAndApp's newsletter. </p>
<form action="subscription.php" name="unsubscribe" method="post"  onsubmit="return isValidEmail()">
<p class="formlabel">E-mail</p> <input type="text" name="unsubscribedmail"/><br/>
<input class="inputsubmit" name="submitbutton" type="submit" value="Unsubscribe"/>
</form>
</div>");

}

mysqli_close($mysqli);

echo("</div>");

?>

当然,我不指望你去检查和调试整个应用程序,但也许更多有经验的人,你知道去哪里寻找。

我在这里开始有点压力......

请告诉我问题是什么以及我如何解决它。

先感谢您!

I am trying to create a web page using php. The problem is that sometimes I get server errors and sometime I get nothing in return at all. At one point the server changed the file type itself. I have NO idea what the problem can be.

And since I have actually no idea what the problem is I paste the entire file here, even though I expect that it's the first few rows that is the problem (I put it here: http://www.iandapp.com/smic/subscription.php) :

<?php header('Content-Type: text/html; charset=ISO-8859-1');

echo("<div id='subscribe'>");

$mail = $_POST['email1'];

//Set the locale format, etc. of date and time
date_default_timezone_set('Europe/Stockholm');
setlocale(LC_TIME, "sv_SV");

//Create the db-connection
$mysqli = mysqli_connect("mydb", "myuser", "mupsw", "myschema", "3306");

//If verifying the subscription, makse sure the db is updated accordingly
if($_GET['newid'] != ""){
    //Make the subscriber a verified subscriber
    $result = mysqli_query($mysqli,"UPDATE users SET subscriber = 1 WHERE id = " . $_GET['newid']);
    if($result){
        echo("<p>Welcome to our newsletter! We will send you information about any new application or update. This will not happen too often, but once it does we hope you will have the opportunity to look into our site again.<p/>");
        echo("<p><br/>If you wish to unsubscribe from this mail-list, please visit out subscription page: <a href="http://" . $_SERVER['HTTP_HOST'] . "/subscription.php"> http://" . $_SERVER['HTTP_HOST'] . "/subscription.php </a> <p/>");
    }else{
        echo("<p>Somthing went wrong, please click the link again!<p/>");
    }

}elseif($_POST['email1'] != ""){ //Only do things if there is an e-mail posted

    //Make sure the ID is unique
    do{
        $rand_int = rand(100000000, 999999999);
        $result = mysqli_query($mysqli, "SELECT id FROM users WHERE id = " . $rand_int);

        $no_of_rows = mysqli_num_rows($result);

        }while($no_of_rows != 0);
    echo("RAND :".$rand_int);

    //Create query for saving the new user e-mail
    $query = "INSERT INTO users(id, email, first_name, surname) VALUES ('" . $rand_int . "', '".$_POST['email1']."', '". $_POST['first_name']."','".$_POST['surname']."')";
    $re = mysqli_query($mysqli, $query);
    echo("Result: ".$re);

    //Check if mail already exist (Error code 1062 = dublicate entries for unique fields)
    $existing = 0;
    if(mysqli_errno($mysqli)==1062){
        echo("It seems like your e-mail already is registered. Perhaps you have been a subscriber earlier? By clicking the link that you will receive in your mail box you subscribe to the newsletter again. ");
        $existing = 1;
        $result = mysqli_query($mysqli,"SELECT id FROM users WHERE email = '" . $_POST['email1'] . "'");
        $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
        $rand_int = $row['id'];
        mysqli_query($mysqli,"UPDATE users SET waiting_for_unsubscribe = 0 WHERE email = '" . $_POST['email1'] . "'");
        if(mysqli_errno($mysqli)){
        echo("Error code " . mysqli_errno($mysqli) . "<br/>");
        echo("Error text " . mysqli_errno($mysqli) . "<br/>");
    }
        //echo("ID------ " . $row['id'] . " ri---- " . $rand_int);
    }



    //Create the link for the user to verify the subscription
    $url = "http://" . $_SERVER['HTTP_HOST'] . "/smic/subscription.php?newid=" . $rand_int;     


    $mymail = $_POST['email1'];
    $esubject = "Please verify your subscription to iAndApp's newsletter ";
    $body = "Click the link in order to verify your subscription (If you cannot click the link, just copy it and paste it into the adress field of your browser): " . $url;
    $eemail = "[email protected]";
    $sent = mail($mymail,$esubject,$body,"From: $eemailn");
    if($sent){
        if($existing != 1){
            echo "<br/>An e-mail with a link has been sent to ". $mymail . ". Please click the link in order to verify your subscription";
        }
    }else{
        echo "Something went wrong. Please try again and make sure you enter a correct e-mail adress.";
    }
    $existing = 0;

mysqli_free_result($result);

//If unsubscribing
}elseif($_POST['unsubscribedmail'] != ""){
    //echo("Unsubscribe........");
    //echo($_POST['unsubscribedmail']);
    $result = mysqli_query($mysqli,"UPDATE users SET waiting_for_unsubscribe = 1 WHERE email = '" . $_POST['unsubscribedmail'] . "'");

    //echo("Err code " . mysqli_errno($mysqli));
    //echo("Err text " . mysqli_error($mysqli));
    if(mysqli_errno($mysqli)){
        echo("Error code " . mysqli_errno($mysqli) . "<br/>");
        echo("Error text " . mysqli_errno($mysqli) . "<br/>");
    }

    $result = mysqli_query($mysqli,"SELECT id FROM users WHERE email = '" . $_POST['unsubscribedmail'] . "'");
    $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
    //echo("ID------ " . $row['id']);
    //Create the link for the user to verify that he/she  unsubscribes
    $url = "http://" . $_SERVER['HTTP_HOST'] . "/smic/subscription.php?unsubscribeid=" . $row['id'];

    $mymail = $_POST['unsubscribedmail'];
    $esubject = "Please verify that you want to unsubscribe from iAndApp's newsletter ";
    $body = "Click the link in order to verify that you want to unsubscribe from iAndApp's newsletter (If you cannot click the link, just copy it and paste it into the adress field of your browser): " . $url;
    $eemail = "[email protected]";
    $sent = mail($mymail,$esubject,$body,"From: $eemailn");
    if ($sent) echo "<br/>A mail with a link has been sent to ". $mymail . ". Please click the link in order to verify that you will unsubscribe from the newsletters.";
    else echo "Something went wrong. Please try again and make sure you enter a correct e-mail adress.";

mysqli_free_result($result);    
}elseif($_GET['unsubscribeid'] != ""){
    $result = mysqli_query($mysqli,"UPDATE users SET subscriber = 0, waiting_for_unsubscribe = 0 WHERE id = " . $_GET['unsubscribeid']);
    if($result){
        echo("<p>You have now unsubscribed to the newsletter. Thank you for this time and we hope to see you again in the future. /iAndApp.<p/>");
    }else{
        echo("<p>Somthing went wrong, please click the link again!<p/> ".$result);
    }

}else{

echo("<div class="subscribe">
<h4>Subscribe</h4>
<p>Subscribe to iAndApp's newsletter in order to get information about new and updated iPhone games and iPhone applications, that has been released by iAndApp. </p>
<form action="subscription.php" name="subscribe" method="post"  onsubmit="return isValidEmailAndEqual()">
<p class="formlabel">Förnamn</p> <input type="text" name="first_name"/><br/>
    <p class="formlabel">Efternamn</p> <input type="text" name="surname"/> <br/>
<p class="formlabel">E-mail</p> <input type="text" name="email1"/>
<br/>
<p class="formlabel">Repeat e-mail</p> <input type="text" name="email2"/> <br/>
<input class="inputsubmit" type="submit" value="Subscribe"/>
</form>
</div>");

echo("<div class="footer"></div>");


echo("<div class="subscribe">
<h4>Unsubscribe</h4>
<p>Fill in your e-mail address and submit in order to unsubscribe from iAndApp's newsletter. </p>
<form action="subscription.php" name="unsubscribe" method="post"  onsubmit="return isValidEmail()">
<p class="formlabel">E-mail</p> <input type="text" name="unsubscribedmail"/><br/>
<input class="inputsubmit" name="submitbutton" type="submit" value="Unsubscribe"/>
</form>
</div>");

}

mysqli_close($mysqli);

echo("</div>");

?>

Of course, I don't expect you to go through and debug the entire application, but perhaps for the more expreienced folks out there, you know where to look.

I'm starting to get a bit stressed out here...

Please advice what the problem is and how I can solve it.

Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

墨小沫ゞ 2024-12-01 16:40:29

代码错误:

echo("<div class="subscribe">
<h4>Subscribe</h4>
<p>Subscribe to i

在第一行中,您只需用第二个引号关闭字符串
你只需要更正代码

eror in code:

echo("<div class="subscribe">
<h4>Subscribe</h4>
<p>Subscribe to i

in 1-st line you just close the string by 2-nd quote
you just need to correct code

暗藏城府 2024-12-01 16:40:29

您必须在 html 标签内转义双引号或使用单引号。现在,echo 认为它在 "

echo "<div class=\"class\">";

echo '<div class="class">';

echo "<div class='class'>";

You have to escape double quotes inside html tags or use single quotes. Right now, echo thinks it's closed after "<div class=". Use one of these:

echo "<div class=\"class\">";

or

echo '<div class="class">';

or

echo "<div class='class'>";
梦罢 2024-12-01 16:40:29

如果您没有从服务器获得任何回复(文档是清晰的)或者您有服务器错误,但这并非总是如此,有时脚本工作正常,这可能是内存限制问题。

do{
    $rand_int = rand(100000000, 999999999);
    $result = mysqli_query($mysqli, "SELECT id FROM users WHERE id = " . $rand_int);

    $no_of_rows = mysqli_num_rows($result);

    }while($no_of_rows != 0);

这部分代码对我来说看起来不太好,我建议您在数据库中的 id 字段中使用 auto_increment (这样 id 将始终是唯一的)

If you dont get any reposne from server (document is clear) or you have server errors but this is not all the time and sometimes script works fine it could be memory limit problem.

do{
    $rand_int = rand(100000000, 999999999);
    $result = mysqli_query($mysqli, "SELECT id FROM users WHERE id = " . $rand_int);

    $no_of_rows = mysqli_num_rows($result);

    }while($no_of_rows != 0);

This part of code dosn't look good for me, I suggest you to use auto_increment at id field in db (so id will be unique all the time)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文