用户提交表单后获取ID时遇到问题

唐尼

在此部分开始说谢谢,您的请求已发送,我可以保留除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> 

创建.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>";


?>

宝ao

改变这部分

<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_!

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

用户在初次提交后尝试重新提交时遇到问题

来自分类Dev

使用AJAX提交表单时遇到问题

来自分类Dev

在模块中使用用户表单时遇到问题

来自分类Dev

使用Spring获取表单数据时遇到问题

来自分类Dev

获取Azure AD用户的组时遇到问题

来自分类Dev

我在获取插入多个下拉值时遇到问题。提交后出现数据库错误

来自分类Dev

从foreach获取价值时遇到问题

来自分类Dev

从foreach获取价值时遇到问题

来自分类Dev

将 HTML/JavaScript 表单的答案保存到用户指定的 .txt 文件时遇到问题

来自分类Dev

在获取<select>值到表单字段时遇到问题

来自分类Dev

从 2 个数组填充的下拉列表中获取表单值时遇到问题

来自分类Dev

Java Array List - 从用户获取值时遇到问题,但程序在不知不觉中终止

来自分类Dev

使用Visual Studio提交到git时遇到问题

来自分类Dev

使用Visual Studio提交到git时遇到问题

来自分类Dev

提交到 SQLite 数据库时遇到问题

来自分类Dev

在我从ajax调用中追加数据后,调用ID时遇到问题

来自分类Dev

使用jQuery + PHP进行表单处理时遇到问题

来自分类Dev

使用jQuery + PHP进行表单处理时遇到问题

来自分类Dev

jQuery序列化表单时遇到问题

来自分类Dev

从Angular Controller访问表单时遇到问题

来自分类Dev

在自动完成功能上从JSON获取ID时遇到问题

来自分类Dev

我在使用拖放API获取元素ID时遇到问题

来自分类Dev

在Laravel中创建用户时遇到问题

来自分类Dev

在C#中创建用户控件时遇到问题

来自分类Dev

在Django中注销用户时遇到问题

来自分类Dev

JDBC在为mysql创建用户时遇到问题

来自分类Dev

检查用户控件类型时遇到问题

来自分类Dev

获取网站的https证书时遇到问题

来自分类Dev

使用ElementTree获取XML元素时遇到问题

Related 相关文章

  1. 1

    用户在初次提交后尝试重新提交时遇到问题

  2. 2

    使用AJAX提交表单时遇到问题

  3. 3

    在模块中使用用户表单时遇到问题

  4. 4

    使用Spring获取表单数据时遇到问题

  5. 5

    获取Azure AD用户的组时遇到问题

  6. 6

    我在获取插入多个下拉值时遇到问题。提交后出现数据库错误

  7. 7

    从foreach获取价值时遇到问题

  8. 8

    从foreach获取价值时遇到问题

  9. 9

    将 HTML/JavaScript 表单的答案保存到用户指定的 .txt 文件时遇到问题

  10. 10

    在获取<select>值到表单字段时遇到问题

  11. 11

    从 2 个数组填充的下拉列表中获取表单值时遇到问题

  12. 12

    Java Array List - 从用户获取值时遇到问题,但程序在不知不觉中终止

  13. 13

    使用Visual Studio提交到git时遇到问题

  14. 14

    使用Visual Studio提交到git时遇到问题

  15. 15

    提交到 SQLite 数据库时遇到问题

  16. 16

    在我从ajax调用中追加数据后,调用ID时遇到问题

  17. 17

    使用jQuery + PHP进行表单处理时遇到问题

  18. 18

    使用jQuery + PHP进行表单处理时遇到问题

  19. 19

    jQuery序列化表单时遇到问题

  20. 20

    从Angular Controller访问表单时遇到问题

  21. 21

    在自动完成功能上从JSON获取ID时遇到问题

  22. 22

    我在使用拖放API获取元素ID时遇到问题

  23. 23

    在Laravel中创建用户时遇到问题

  24. 24

    在C#中创建用户控件时遇到问题

  25. 25

    在Django中注销用户时遇到问题

  26. 26

    JDBC在为mysql创建用户时遇到问题

  27. 27

    检查用户控件类型时遇到问题

  28. 28

    获取网站的https证书时遇到问题

  29. 29

    使用ElementTree获取XML元素时遇到问题

热门标签

归档