我有php頁面輸入審計的一些細節,最後保存在database.But當我輸入的數據,並按保存按鈕。但它不會保存在數據庫中。當我使用error_log()函數來檢查php函數是否正在工作或不在下面時,在我的日誌文件中只有「已啓動」的地方..他們沒有「提交」和進一步的數據庫錯誤信息。數據不保存在MySQL使用PHP
注:即時通訊新的PHP,開始開發PHP應用程序中使用XAMPP和記事本+
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>";
}
?>
你得到了什麼數據庫錯誤?如果你是PHP的新手,那麼停止學習不推薦使用的mysql,而應該使用'mysqli或者PDO' – Saty
建議:'mysql_ *'已經過時並且從PHP中刪除。使用[mysqli](http://php.net/manual/en/book.mysqli.php)或[PDO](http://php.net/manual/en/ref.pdo-mysql.php) – bansi