我是PHP MySQL的初学者,我想问一下这是否可能:
我有ADD NEW EMPLOYEE页面后,我提交,我想有简单的汇总信息的添加的员工,如
比如打开一个新窗口:
Agent Code:
新增员工的Agent Code
Name:
员工姓名
类型:
类型的员工
这是PHP代码在我的ADD NEW EMPLOYEE页面:
<?php
session_start();
include_once 'dbconnect.php';
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
$res=mysql_query("SELECT * FROM accounts WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
if(isset($_POST['btn-signup']))
{
$agentCode = mysql_real_escape_string($_POST['agentCode']);
$pass = md5(mysql_real_escape_string($_POST['pass']));
$aFName = mysql_real_escape_string($_POST['aFName']);
$aLName = mysql_real_escape_string($_POST['aLName']);
$aMName = mysql_real_escape_string($_POST['aMName']);
$aSuffixName = mysql_real_escape_string($_POST['aSuffixName']);
$aContact = mysql_real_escape_string($_POST['aContact']);
$aAddress = mysql_real_escape_string($_POST['aAddress']);
$aGender = mysql_real_escape_string($_POST['aGender']);
$utype = mysql_real_escape_string($_POST['utype']);
$loctype = mysql_real_escape_string($_POST['loctype']);
$ipadd = mysql_real_escape_string($_POST['ipadd']);
if(mysql_query("INSERT INTO accounts(agentCode, password, agentFname, agentMname, agentLname, aSuffixName, agentContact, agentAddress, agentGender, user_type, location_type, ip_add)
VALUES('$agentCode', '$pass', '$aFName', '$aMName', '$aLName', '$aSuffixName', '$aContact', '$aAddress', '$aGender', '$utype', '$loctype', '$ipadd' )"))
{
?>
<script>alert('Successfully added!');</script>
<?php
} else {
?>
<script>alert('Agent Code is not available!');</script>
<?php
}
}
?>
有两种方法。
1)您将从用于将值插入到数据库的表单中发布所有数据库。您可以使用相同的值来显示。
mysql_*
, mysqli_*
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$qry = "INSERT INTO accounts(agentCode, password, agentFname, agentMname, agentLname, aSuffixName, agentContact, agentAddress, agentGender, user_type, location_type, ip_add)
VALUES('$agentCode', '$pass', '$aFName', '$aMName', '$aLName', '$aSuffixName', '$aContact', '$aAddress', '$aGender', '$utype', '$loctype', '$ipadd' )";
mysqli_query($con, $qry);
// Print auto-generated id
$last_inserted_id = mysqli_insert_id($con);
echo "Last Inserted ID: " . $last_inserted_id;
// Now you can perform a select query by using this ID and show
// Agent Code: The Agent code of the employee newly added
// Name: Name of the Employee
// Type: Type of the employee
mysqli_close($con);