1

以下は私のコードで、とという名前の2つのテキストボックスがfyearありayearます。MySQLデータベースに接続できないため、このコードは機能していません。何が問題なのか、どうすればそれを克服できますか?私はPHPを使用しています:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Home</title>
</head>



<body style="background-color:#708090;">

<?php

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

    $mysqli= new mysqli("localhost","admin","admin", "nba" );

    if($mysqli === false)
    {
        die("could not connect:" . mysqli_connect_error());
    }

    if ($inputError != true && empty($_POST['ayear']) )
    {
        echo 'ERROR: Please enter a valid year';
        $inputError = true;
    }
    else
    {
        $ayear = $mysqli-> escape_string($_POST['ayear']);
    }

    if ($inputError != true && empty($_POST['fyear']) )
    {
        echo 'ERROR: Please enter a valid year';
        $inputError = true;
    }
    else
    {
        $fyear = $mysqli->  escape_string($_POST['fyear']);
    }   

    if ($inputError != true)
    {
        $sql="INSERT INTO year VALUES ('$ayear','$fyear')";
        if ($mysqli-> query($sql)==true)
        {
            echo'Added';
        }
        else
        {
            echo"ERROR: Could not execute query : $sql. " . $mysqli-> error;
        }
    }

    $mysqli-> close();

}
?> 







<h1 style="font-family:Verdana;text-align:center;">National Board of Accrediation <br>of<br> Master of Computer Applications Programme</h1>
<br>

<div id="menu" style="background-color:#800000;height:25px;width:1000px">
<b><font "style="font-family:Verdana"><a href="part1.html" title="Institutional Summary"style="color: #000000">Part I</a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<a href="part2.html"title="Departmental/Program Summary"style="color: #000000">Part II</a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<a href="part3.html"title="Curricula,Syllabi,PEOs and POs"style="color: #000000">Part III</a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<a href="part4.html" title="List of Documents to be made available during the visit"style="color: #000000">Part IV</a></font></b>
</div>


<form   method="post" action="home.php"> <p> This  Report  is prepared for the Current Acadamic Year(<input type="text" size="9"  name="ayear" id="ayear" onChange="a('ayear');">) and the Current Financial Year (<input type="text" size="9"  name="fyear" id="fyear" onChange="a('fyear');">) on behalf of the Institution.</p>



<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>

問題はこの部分からです:

else
        {
            $ayear = $mysqli-> escape_string($_POST['ayear']);
        }

">"記号の後、すべてがWebページに印刷されます。これに対する可能な解決策は何でしょうか?私はこのコードを調べましたが、間違いが何であるかを見つけることができませんでした。

4

1 に答える 1

1

PHPはスクリプトをまったく処理しなかったため<?php ... ->、HTMLタグとして解釈されました。ブラウザでHTMLソースコードを確認してください。

スクリプトは次のように保存され.phpますか?PHPはサーバーにインストールされていますか?

于 2013-01-29T08:52:36.987 に答える