The following is my code, in which I have 2 text boxes named fyear and ayear. This code is not working, as, I am unable to connect it with the MySQL database. What might be the problem and how could I overcome it? I’m using 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>               <a href="part2.html"title="Departmental/Program Summary"style="color: #000000">Part II</a>               <a href="part3.html"title="Curricula,Syllabi,PEOs and POs"style="color: #000000">Part III</a>               <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>
The problem is from this part:
else
{
$ayear = $mysqli-> escape_string($_POST['ayear']);
}
After the “>” symbol, everything is getting printed in the web page. What could be the possible solution for this? I’ve gone through this code but couldn’t find out what the mistake is.
PHP did not process your script at all, so that
<?php ... ->was interpreted as a HTML tag. Look at the HTML source code in your browser.Is the script saved as
.php? Is PHP installed on your server?