HI,
I have created a form where user can input some values with 2 buttons submit and clear. Then in the same form I have added php code for submit button , if this button is clicked, a seperate php page is called which has some functions written in it. One of the functions in the page include connecting to database, table and command to insert a record from the data entered in the form. However when I run it and click on submit the page just refrehes and nothing is added to my database. Can someone please tell me what could be the problem. Here are the codes for reference.
page 1
<html>
<head>
<title>Enter Session Details Here</title>
<script language="javascript" type="text/javascript" src="datetimepicker.js"> //Date Time Picker script
</script>
<? include("db_ops.php3"); ?>
</head>
<body>
<form method="POST" name="stdFrm" action="sessionDetailsEntry.php3">
<U><B><CENTER>Session Information Entry</CENTER></B></U>
<TABLE align="center">
<TR>
<TD>Teacher:</TD>
<TD><input type=text name="teacherName" size="25" maxlength="25"</TD>
</TR>
<TR>
<TD>Student Name:</TD>
<TD><input type=text name="studentName" size="10" maxlength="10" maxlength="10"></TD>
</TR>
<TR>
<TD>Topic Taught:</TD>
<TD><input type=text name="topic" size="25" maxlength="25"></TD>
</TR>
<TR>
<TD>Session Date and Time:</TD>
<TD><input id="sessionDateTime" type="text" size="25"><a href="javascript:NewCal('sessionDateTime','ddmmyyyy',true, 12)"><img src="cal.gif" width="16" height="16" border="0" ></a></TD>
</TR>
<TR>
<TD>Assignment Score:</TD>
<TD><input type=text name="score" size="10" maxlength="10"></TD>
</TR>
<TR>
<TD>Comments:</TD>
<TD><textarea name="comments" cols=80 rows=4 maxlength="500"></textarea></TD>
</TR>
<TR>
<TD>Technical Issues:</TD>
<TD><textarea name="technicalIssues" cols=80 rows=4 maxlength="300"></textarea></TD>
</TR>
<TR>
<TD>Next Topic:</TD>
<TD><input type=text name="nextTopic" size="25" maxlength="25"></TD>
</TR>
<TR>
<TD align="right"><input type="Submit" value="Save"></TD>
<TD align="left"><input type="reset" value="Clear"></TD>
</TR>
</TABLE>
</form>
<? php
if(isset($_POST['Submit']))
{
$table_nm = 'session_entry';
add_to_table(table_nm);
echo "Back";
}
?>
</body>
</html>
page 2 with functions
<html>
<body>
<?php
$link;
function add_to_table($table_nm)
{
connect_to_db();
mysql_select_db('etz', $link);
$add_to_table = "INSERT INTO session_entry (teacher_id, student_id, topic, assignment_score, comments, session_issues, next_topic, date, timestamp) VALUES ('$_POST[teacherName]', '$_POST[studentName]', '$_POST','$_POST[score]', '$_POST[comments]', '$_POST[technicalIssues]', '$_POST[nextTopic]', '$_POST[sessionDateTime]', '$_POST[sessionDateTime]')";
echo "Adding the records";
mysql_query ($ad_to_table) or die(mysql_error());
mysql_close($link);
}
function connect_to_db()
{
$link = mysql_connect('localhost' , 'root' , '' );
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
echo 'connected successfully' . "\n" ;
}
?>
TIA