在该部分开始说谢谢你的请求已被发送我可以保留除id号和date_requested之外的所有表单信息。不确定如何获取提交的ID号。至于请求日期我可能会为此添加日期时间戳。关于我能做什么的任何建议?谢谢
insert_process.php
<html>
<head>
<title></title>
</head>
<body></body>
</html>
<?php
error_reporting(E_ERROR | E_PARSE);
$host = "localhost";
$user = "root";
$db_name= "systems_requests";
$pass= "systems399";
$con = mysql_connect($host, $user, $pass);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("systems_requests", $con);
$lanId= mysql_real_escape_string($_POST['lanId']);
$name= mysql_real_escape_string($_POST['name']);
$department= mysql_real_escape_string($_POST['department']);
$manager= mysql_real_escape_string($_POST['manager']);
$request= mysql_real_escape_string($_POST['request']);
$request_description= mysql_real_escape_string($_POST['request_description']);
$request_comments= mysql_real_escape_string($_POST['request_comments']);
$status= mysql_real_escape_string($_POST['status']);
$comments= mysql_real_escape_string($_POST['comments']);
$compUser= mysql_real_escape_string($_POST['compUser']);
$compDt= mysql_real_escape_string($_POST['compDt']);
$sql="INSERT INTO requests(lanId, name, department, manager, request, request_description, request_comments, status, comments, compUser, compDt) VALUES ('$lanId','$name', '$department', '$manager','$request','$request_description','$request_comments','$status', '$comments','$compUser','$compDt')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
mysql_close($con);
?>
<html>
<body>
<br><br><br><br><br>
<p align="center">THANK YOU, <?php echo $_POST["name"]; ?><br>
Your request Has been Sent. Your request number is <?php $_POST["id"];?><br>
Please write this number down or print this page out.</p>
<div align="center">
<h2>Request Information</h2>
Date Request: <?php echo $_POST["date_requested"]; ?><br>
Manager: <?php echo $_POST["manager"]; ?><br>
Location: <?php echo $_POST["department"]; ?><br>
Request Issue: <?php echo $_POST["request"]; ?> <?php echo $_POST["request_description"]; ?><br>
Request Comments: <?php echo $_POST["request_comments"]; ?><br>
</div>
<div align="center">
<h2>Status Information</h2>
Status: <?php echo $_POST["status"]; ?><br>
</div>
</body>
</html>
Create.php
<!DOCTYPE html>
<html>
<head>
<title>Systems Request </title>
<script type="text/javascript" src="Javascript/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="Javascript/ShowTextbox.js"></script>
<script type="text/javascript" src="Javascript/textboxname_autocomplete.js"></script>
<link href="css/create.css" rel="stylesheet" type="text/css" >
</head>
<body style="background-image: url('../Systems/images/background.jpg')">
<h1 class="h1">Systems Request<br><br></h1>
<div align="center">
<form action = "insert_process.php" method ="post" class="form" style="width: 467px; height: 575px">
<br><br>Lan ID<br>
<input type="text" id="lanId" name="lanId">
<br>Name<br>
<input type="text" id="name" name="name" >
<?php #start of the department location if you need to add another department copy any option value and change the name to the depart desired.?>
<br>Department Location<br>
<select name ="department" style="width: 160px"onchange="showfield(this.options[this.selectedIndex].value)" >
<option value ="">Please select ...</option>
<option value ="Other">Other</option>
</select><br>
<?php #end of the department location ?>
<?php /*start of manager section if you need to add a manager copy the option value and change the name.
If you need to change a manager just change the name*/ ?>
<br>Manager<br>
<select name ="manager" style="width: 160px" >
<option value ="">Please select ...</option>
<?php # end of manager section ?>
<?php #start of Request Issues ?>
</select>
<br>Request Issue<br>
<select name ="request" style="width: 160px"onchange="showfield(this.options[this.selectedIndex].value)">
<option value ="">Please select ...</option>
<option value ="Reset Case">Reset Case</option>
<option value ="Reset WM Password">Reset WM Password</option>
<option value ="Replace Toner">Replace Toner</option>
<option value ="Fix Printer">Fix Printer</option>
<option value ="Safety High Request">Safety High request</option>
<option value ="Other">Other</option>
</select>
<br>
<?php /* to add an extra option you need to add a new div and go to showtextbox.js and
add a new line and just change div to the next one which would be div6 also you have to make sure the value matches.*/?>
<?php #reset case?>
<div id="div1"></div>
<?php #reset WM password?>
<div id="div2"></div>
<?php #replace toner?>
<div id="div3"></div>
<?php #Other ?>
<div id="div4"></div>
<?php #Saftey High Request?>
<div id="div5"></div>
<?php #fix printer?>
<div id="div6"></div>
<?php #end of request issue section?>
<br>
Describe the issue of your request ? <br>Exact Location, Printer Name, etc<br>
<textarea name="request_comments" style="width: 353px; height: 81px" ></textarea><br><br>
<input type="submit" value= "Submit Request "><br>
<?php #Hidden inputs for Status, tech comments, tech completed, tech completed date?>
<input type="hidden" name="status" value="Received" >
<input type="hidden" name="comments" value="No_Comments">
<input type="hidden" name="compUser" value="Unassigned" >
<input type="hidden" name="compDt" value="Not Completed" >
</form>
</div>
</body>
</html>
<?php
error_reporting(E_ERROR | E_PARSE);
echo "<h2 align='center'>";
echo "Reminder" . "<br>";
echo "For Computer password Resets call helpdesk ";
echo "</h2>";
?>
答案 0 :(得分:1)
更改此部分
<p align="center">THANK YOU, <?php echo $_POST["name"]; ?><br>
Your request Has been Sent. Your request number is <?php $_POST["id"];?><br>
Please write this number down or print this page out.</p>
到
<p align="center">THANK YOU, <?php echo $_POST["name"]; ?><br>
Your request Has been Sent. Your request number is <?php echo $id;?><br>
Please write this number down or print this page out.</p>
在插入查询后直接从表中选择max(id):
SELECT id FROM requests WHERE id = SELECT max(id) FROM requests
并将其置于变量
中$id
修改
把它放在
之后$sql="INSERT INTO requests(lanId, name, department, manager, request, request_description, request_comments, status, comments, compUser, compDt) VALUES ('$lanId','$name', '$department', '$manager','$request','$request_description','$request_comments','$status', '$comments','$compUser','$compDt')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
之前
mysql_close($con);
修改
这是您的整个文件,只需复制此
即可<html>
<head>
<title></title>
</head>
<body></body>
</html>
<?php
error_reporting(E_ERROR | E_PARSE);
$host = "localhost";
$user = "root";
$db_name= "systems_requests";
$pass= "systems399";
$con = new mysqli($host, $user, $pass, $db_name);
$lanId= mysqli_real_escape_string($con,$con,$_POST['lanId']);
$name= mysqli_real_escape_string($con,$_POST['name']);
$department= mysqli_real_escape_string($con,$_POST['department']);
$manager= mysqli_real_escape_string($con,$_POST['manager']);
$request= mysqli_real_escape_string($con,$_POST['request']);
$request_description= mysqli_real_escape_string($con,$_POST['request_description']);
$request_comments= mysqli_real_escape_string($con,$_POST['request_comments']);
$status= mysqli_real_escape_string($con,$_POST['status']);
$comments= mysqli_real_escape_string($con,$_POST['comments']);
$compUser= mysqli_real_escape_string($con,$_POST['compUser']);
$compDt= mysqli_real_escape_string($con,$_POST['compDt']);
mysqli_query($con,"INSERT INTO requests(lanId, name, department, manager, request, request_description, request_comments, status, comments, compUser, compDt) VALUES ('$lanId','$name', '$department', '$manager','$request','$request_description','$request_comments','$status', '$comments','$compUser','$compDt')");
$sql = "SELECT id FROM requests WHERE id = (SELECT max(id) FROM requests)";
if ($result = $con->query($sql))
{
while ($row = $result->fetch_assoc()) {
$id = $row['id'];
}
}
$con->close();
?>
<html>
<body>
<br><br><br><br><br>
<p align="center">THANK YOU, <?php echo $_POST["name"]; ?><br>
Your request Has been Sent. Your request number is <?php echo $id;?><br>
Please write this number down or print this page out.</p>
<div align="center">
<h2>Request Information</h2>
Date Request: <?php echo $_POST["date_requested"]; ?><br>
Manager: <?php echo $_POST["manager"]; ?><br>
Location: <?php echo $_POST["department"]; ?><br>
Request Issue: <?php echo $_POST["request"]; ?> <?php echo $_POST["request_description"]; ?><br>
Request Comments: <?php echo $_POST["request_comments"]; ?><br>
</div>
<div align="center">
<h2>Status Information</h2>
Status: <?php echo $_POST["status"]; ?><br>
</div>
</body>
</html>
有什么区别?
我刚刚开始将它改为mysqli_,忘了mysql_并学习mysqli _!