ctimings.html
<html>
<head>
<link rel="stylesheet" type="text/css" href="cstyle.css">
// <script type="text/javascript">
// function validate(form)
// {
// if(document.myForm.sno.value == "")
// {
// alert("Please Complete Serial NUmber");
// return false;
// }
// if(document.myForm.ssign.value == "")
// {
// alert("Please Complete Signature");
// return false;
// }
// if(document.myForm.empName.value == "")
// {
// alert("Please Complete Employee Name");
// return false;
// }
// if(document.myForm.empSign.value == "")
// {
// alert("Please Complete Employee Signature");
// return false;
// }
// if(document.myForm.empCode.value == "")
// {
// alert("Please Complete Employee Code");
// return false;
// }
// }
// </script>
<title>Conference Room Timings</title>
</head>
<body>
<form action = "ctimings.php" method = "post" name = "myForm" onsubmit="return validate(this);">
<legend>ADD DETAILS</legend>
<fieldset>
<label>Serial Number <input type = "int" name = "sno" size="20" class = "required" /></label><br/>
<label>Security Signature <input type = "text" name = "ssign" size="20" class = "required" /></label><br/>
<legend>Employee Details</legend>
<fieldset>
<label>Employee Name <input type = "text" name = "empName" size="20" class = "required" /></label><br/>
<label>Employee Signature <input type = "text" name = "empSign" size="20" class = "required"/></label><br/>
<label>Employee Code <input type = "int" name = "empCode" size="20" class = "required" /></label><br/>
</fieldset>
<legend>Date & Time</legend>
<fieldset>
<label>Date <input type = "int" name = "date" size="20" class = "required"/></label><br/>
<label>In - Time <input type = "int" name = "inTime" size="20" class = "required"/></label><br/>
<label>In - Time <input type = "int" name = "outTime" size="20" class = "required"/></label><br/>
</fieldset>
<legend>Usage</legend>
<fieldset>
<label>
Phone Set Usage
<input type = "radio" name = "radio1" value = "YES" />
<input type = "radio" name = "radio1" value = "NO" /><br/>
</label>
<label>
Projector Usage
<input type = "radio" name = "radio2" value = "YES" />
<input type = "radio" name = "radio2" value = "NO" /><br/>
</label>
</fieldset>
<input type = "submit" value = "SUBMIT" class = "" name = "SUBMIT"/>
</fieldset>
</form>
</body>
</html>
ctimings.php
<html>
<body>
<?php
if(isset($_POST['SUBMIT']))
{
echo "pressed";
$db_host = "localhost";
$db_username = "root";
$db_pass = "";
$db_name = "ibm";
$con=mysql_connect("localhost","root","","ibm");
// Check connection
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Not connected : ' . mysql_error());
}
else
{
echo 'Connection was OK';
}
$db_selected = mysql_select_db($db_name, $link);
if (!$db_selected) {
die ('Can\'t use ibm : ' . mysql_error());
}
else
{
echo "Database was OK!\n";
}
$sql = "INSERT INTO ctimings(sno,ssign,empName,empSign,date,intime,outtime,empCode,Proj.Use,Ph.Use) VALUES('$_POST[sno]','$_POST[ssign]','$_POST[empName]','$_POST[empSign]','$_POST[date]','$_POST[inTime]','$_POST[outTime]','$_POST[empCode]','$_POST[radio1]','$_POST[radio2]')";
mysql_query($sql,$link);
mysql_close($link);
}
else
echo 'error';
?>
</body>
</html>
これは簡単な手順ですが、phpmyadmin テーブル「ctimings」にレコードがないことが示されているため、データがデータベースに送信されない理由を絞り込むことができません。送信ボタンが押された後、データベースにデータを送信しますが、無駄です。データベース名とデータベース内のテーブル名は正しいです。