i have a form ("aud.php") with 3 fields: YEAR: can be(fe,se,te,be) SEMESTER: can be (1 or 2) SUBJECT: can be (any VARCHAR datatype)
Now, i have a database ("einternals") with four tables (fe,se,te,be). Each table has 2 fields (sem1 or sem2). The problem is when i submit the form, the data is not getting inserted into the databse.
HERE"S the "aud.php" file:
$con = mysql_connect("localhost","root","","einternals");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
echo "Go ahead and edit";
}
?>
<html>
<body background="bg1.jpg">
<h2 align="left"><a href="logout.php">LOGOUT</a></h2>
<form action="add.php" method="post">
<h1 align="center"><u>ADD A SUBJECT</u></h1>
<p align="center">    YEAR: <input type="text" name="year" required/></p><br>
<p align="center">SEM: <input type="text" name="sem" required/></p><br>
<p align="center">  SUBJECT: <input type="text" name="subject" required /></p><br>
<p align="center"><input type="submit" value="ADD" /></p>
</form>
<form action="delete.php" method="post">
<h1 align="center"><u>DELETE A SUBJECT</u></h1>
<p align="center">    YEAR: <input type="text" name="year" required/></p><br>
<p align="center">SEM: <input type="text" name="sem" required/></p><br>
<p align="center">  SUBJECT: <input type="text" name="subject" required /></p><br>
<p align="center"><input type="submit" value="DELETE" /></p>
</form>
</body>
</html>
HERE's the "add.php" file:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
mysql_select_db("einternals", $con);
if('$_POST[sem]'==1)
{
$sql="INSERT INTO '$_POST[year]'(sem1)
VALUES
('$_POST[subject]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
}
else
{
$sql="INSERT INTO '$_POST[year]'(sem2)
VALUES
('$_POST[subject]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
}
echo "Operation successful";
}
mysql_close($con)
?>