提交两个表格到MYSQL? [英] Submit two forms to MYSQL?

查看:68
本文介绍了提交两个表格到MYSQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在一个页面中有两个表单 - 一个正在工作,但我想知道我是否为第二个执行与下面完全相同的代码?进入两个不同的桌子?



最好的方法是什么?



什么我试过了:



 $ UserID = $ _SESSION ['currentUserID']; 
//使用预准备语句插入数据库
$ stmt = $ conn-> prepare('INSERT INTO MedicalAppointment(Time,Date,Notes,AppointmentType,UserID)VALUES(:Time,:Date, :Notes,:AppointmentType,:UserID)');
$ stmt->执行(数组(
':时间'=> $ _ POST ['时间'],
':日期'=> $ _POST ['日期'] ,
':Notes'=> $ _POST ['注释'],
':AppointmentType'=> $ _ POST ['AppointmentType'],
':UserID'=> $ UserID
));


// $ UserID = $ conn-> lastInsertId('UserID');
ob_start();
//重定向到索引页
echo'< script> window.location =Appointments.php?action = saved;< / script>';



// header(Location:index.php?action = joined);
退出;

//否则捕获异常并显示错误。
} catch(PDOException $ e){
$ error [] = $ e-> getMessage();
}
}
}
?>

解决方案

UserID =

_SESSION [ 'currentUserID'];
//使用预准备语句插入数据库


stmt =


Hi I have two forms in one page - one is working, but i was wondering do i do the exact same code as below for the second? both going into two different tables?

Whats the best way around this?

What I have tried:

$UserID = $_SESSION['currentUserID'];
			//insert into database with a prepared statement
			$stmt = $conn->prepare('INSERT INTO MedicalAppointment (Time, Date, Notes, AppointmentType,UserID) VALUES (:Time, :Date, :Notes, :AppointmentType, :UserID)');
			$stmt->execute(array( 
				':Time' =>$_POST['Time'],
				':Date' => $_POST['Date'],	
				':Notes' => $_POST['Notes'],	
				':AppointmentType' =>$_POST['AppointmentType'],
				':UserID' =>$UserID
				));
				
				
		//$UserID = $conn->lastInsertId('UserID');
			ob_start();
			//redirect to index page
			echo'<script>window.location = "Appointments.php?action=saved";</script>';
		
 
			
			//header("Location: index.php?action=joined");
			exit;

		//else catch the exception and show the error.
		} catch(PDOException $e) {
			$error[] = $e->getMessage();
		}
}
	}	
?>

解决方案

UserID =


_SESSION['currentUserID']; //insert into database with a prepared statement


stmt =


这篇关于提交两个表格到MYSQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆