⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newaction.php

📁 PHP4_0入门与提高源程序代码
💻 PHP
字号:
<?
include "config.php";	//包含配置文件

	$date=date("Y");	//取得当前年份
	//把详细的日期保存到$date中,包括年月日
	$date=$date."-".$month."-".$day;	
	
	//建立与数据库的连接
	$mysql_link = mysql_connect($host,$user,$password);
	//选择数据库
	mysql_select_db($bdd,$mysql_link);

	//向数据库中插入一行内容
	$query = "insert into expenses (money,description,type,date,user) values('$howmuch','$descriptionx','$type','$date','$uservalid')";
	$mysql_result = mysql_query($query, $mysql_link);
	
	//检查数据库中是否有当前用户的当前月份统计记录
	$datemonth=date("Y-m")."-00";	//月份记录中的日期
	//查询数据库中的内容
	$query="select * from monthly where date='$datemonth' and user='$uservalid'";
	$mysql_result = mysql_query($query, $mysql_link);
	$row = mysql_fetch_row($mysql_result);
	
	if ($row[0]!='') { 
					 //当前用户的当前月份的统计记录已经存在
					   if ($type=="in") { 
					   					  //如果新添加的记录为收入
					   					  $newmon=$howmuch+$row[2];
					   					  $column="deposits";
					   					  $newtot=($howmuch)+($row[3]);
					   					}
					   					
					   if ($type=="out"){ 
					   					  //如果新添加的记录为支出
										  $newmon=$howmuch+$row[1];
					   					  $column="expenses";
					   					  $newtot=($row[3])-($howmuch);
					   					}
		//更新monthly表
		$query2="update monthly set $column='$newmon',status='$newtot' where date='$datemonth' and user='$uservalid'";
					   mysql_query($query2, $mysql_link);
					   					
					 }
					 
	else{
		  //当前用户的当前月份的统计记录不存在
		  		  		if ($type=="in") {
										  //如果新添加的记录为收入
										  $newmon=$howmuch;
					   					  $column="deposits";
					   					  $newtot=$howmuch;
					   					}
					   if ($type=="out"){ 
					   					  //如果新添加的记录为支出					 
					   					  $newmon=$howmuch;
					   					  $column="expenses";
					   					  $newtot=(-1*$howmuch);
					   					}
					  //检查是否有上个月份剩余的金额存在
					  //如果有的话,需要补充到本月中
			$querycheck="select * from monthly where user='$uservalid' order by id desc";		  

			$result_check=mysql_query($querycheck, $mysql_link);
		    $rowcheck = mysql_fetch_row($result_check);
		    
			$lastmonth=0;
		    if ($rowcheck[3]!='') 
		      {
		         $lastmonth=$rowcheck[3]; //把上个月的剩余金额保存到$lastmonth中
		      }
			//把上月的剩余加入到本月的金额中
			$newtot=$newtot+$lastmonth;		   	
	$query2="insert into monthly($column,status,date,previous,user) values('$newmon','$newtot','$datemonth','$lastmonth','$uservalid')";
			mysql_query($query2, $mysql_link);
					
					}
?>
<!--把页面重定向到main.php中-->
<meta http-equiv="REFRESH" CONTENT="0;URL=main.php">

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -