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表发送到数据库&#34; ctimings&#34;显示它没有记录。按下提交按钮后,它应该将数据发布到数据库但是徒劳无功。数据库中的数据库名称和表名是正确的。
答案 0 :(得分:0)
$ _ POST是一个全局数组,你必须使用它像$ _POST [“field_name”];
答案 1 :(得分:0)
您的查询就像
$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_real_escape_string
来转义帖子变量主要原因是由于 Proj.Use,Ph.Use 你在我想的时候使用插入两个表,
答案 2 :(得分:0)
您的sql字符串不正确,需要;
$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]."')";
答案 3 :(得分:0)
要添加上述答案,可能需要清理数据。
$_POST = array_map('mysql_real_escape_string', $_POST);