[英]data are not saving in mysql using php
I have php page to enter some details of audit and finally save in database.But when i entered the data,and press the save button.But it doesn't get saved in database.When i use error_log() function to check whether php function is working or not as below, in my log file only "Started" is there.. their is no "submitted" and further database error message. 我有php页面输入一些审计的详细信息,最后保存在数据库中。但是当我输入数据时,按保存按钮。但是它没有保存在数据库中。当我使用error_log()函数检查php是否功能是否正常工作,如下所示,在我的日志文件中只有“已启动” ..没有“已提交”和进一步的数据库错误消息。
Note: im new to php,started to develop php application using xampp and notepad++ 注意:我是php的新手,开始使用xampp和notepad ++开发php应用程序
auditentry.php auditentry.php
<?php
include("config.php");
include("header.php");
session_start();
error_log("started");
?>
<link href="<?=BASE_URL?>bootstrap/css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="<?=BASE_URL?>/bootstrap/css/bootstrap.min.css">
<script type="text/javascript" src="<?=BASE_URL?>js/jquery.js"></script>
<script src="<?=BASE_URL?>bootstrap/js/bootstrap.js"></script>
<link href="<?=BASE_URL?>bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<div class="col-md-10 main">
<h1 class="page-header">
Audit Plan Entry
</h1>
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="control-label col-sm-2" for="usr">Audit ID:</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="auditid" name ="auditid" placeholder="Eg: IA01">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">Year:</label>
<div class="col-sm-5">
<input type="text" class="form-control col-xs-3" id="year" name ="year">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="usr">Month:</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="month" name ="month">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 " for="sel1">Status:</label>
<div class="col-sm-5">
<select class="form-control" id="sel1" name="status">
<option>Planned</option>
<option>Scheduled</option>
<option>Completed</option>
<option>Cancelled</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="comment">Comment:</label>
<div class="col-sm-5">
<textarea class="form-control" rows="3" id="comment" name="comment"></textarea>
</div>
</div>
<div class="form-group">
<div class=" col-sm-offset-3">
<button type="submit" name="submit" id ="submit" class="btn btn-primary">Save</button>
<button type="reset" name="submit1" id ="clear" class="btn btn-primary">Cancel</button>
</div>
</div>
</form>
</div>
<?php
if(isset($_POST['submit']))
{
error_log("Submitted");
if(trim($_POST['auditid'])=='')
{
echo "<script language='javascript'>alert('Please Enter Audit ID.');</script>";
exit;
}
elseif(trim($_POST['year'])=='')
{
echo "<script language='javascript'>alert('Please Enter Year.');</script>";
exit;
}
elseif(trim($_POST['month'])=='')
{
echo "<script language='javascript'>alert('Please Enter Month.');</script>";
exit;
}
elseif(trim($_POST['Status'])=='None')
{
echo "<script language='javascript'>alert('Please Enter Status.');</script>";
exit;
}
$audit=trim($_REQUEST['auditid']);
$year=trim($_REQUEST['year']);
$month=trim($_REQUEST['month']);
$status =$_REQUEST['status'];
$comment=$_REQUEST['comment'];
error_log($audit);
$con = mysql_connect("localhost","root","") or die("Sorry you are not connected to server. Try Again!");
mysql_select_db("simauditdb", $con) or die ("Cannot connect to database.");
$insert= "insert into auditplan
values('','$audit','$year','$month','$status','$comment','1')";
error_log($insert);
$result=mysql_query($insert) or die('Connection Failed'.mysql_error());
echo "<script language='javascript'>alert('Audit Details Entered Successfully');</script>";
mysql_close($con);
}
elseif(isset($_POST['submit1']))
{
echo "<script language='javascript'>document.location.href='Auditplan.php';</script>";
}
?>
You didnt specify the form action and method. 您没有指定表单操作和方法。
<form class="form-horizontal" role="form">
Try this <form class="form-horizontal" role="form">
尝试一下
<form action="" method="post" lass="form-horizontal" role="form">
You are posting the values, but you forgot to specify the form method. 您正在发布值,但是您忘记了指定表单方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.