简体   繁体   English

如何运行查询并重新加载页面?

[英]How can I run query and reload page?

The doubt is the next one...怀疑是下一个……

I have a query that I want to create when entering the page in order to obtain an ID that I want to put in an input to enter records with their respective created id that is unique per day ...我有一个查询,我想在进入页面时创建一个查询,以获得一个 ID,我想输入该 ID 以输入记录,这些记录具有各自创建的每天唯一的 ID ...

The query if the problem is executed is that once the page is loaded it creates it but to get the id, I must refresh the page again and get the id in my inputs, I would like to see the way to create the query and then my Website cool down.执行问题的查询是,一旦页面被加载,它就会创建它,但要获取 id,我必须再次刷新页面并在我的输入中获取 id,我想看看创建查询的方法,然后我的网站冷静下来。

 $QueryLineAdd="INSERT INTO psb_smt.psb_info (linea, DateTime, EndDate) SELECT * FROM (SELECT '".$_GET['line']."', '".$StarDate." ".$TimeNow."', '".$EndDate." 06:39:00') AS tmp WHERE NOT EXISTS ( SELECT DateTime, EndDate, linea FROM psb_smt.psb_info WHERE linea = '".$_GET['line']."' AND DateTime >= '".$StarDate." 06:40:00' AND EndDate<='".$EndDate." 06:39:00' ) LIMIT 1"; $ResultLineAdd=mysqli_query($con,$QueryLineAdd);

If I do get it right, the query that you are executing returns some id, lets say NNN.如果我做对了,您正在执行的查询会返回一些 id,比如说 NNN。 Make sure you have no output on that page and then just do a header location:确保该页面上没有输出,然后只执行标题位置:

header("Location: http://www.example.com/?id=NNN");

If you have output before that you will get headers already sent warning and you will not be able to redirect.如果您在此之前有输出,您将收到标题已发送警告,并且您将无法重定向。

you don't refresh a page because of an ID.您不会因为 ID 而刷新页面。 you either pass it as an encrypted query string like https://example.com/somepage?id=AXYHNJK76PLOUY09YTTV4CDF let's say id here is 2 then grab it by $id = $_GET['id'].您要么将其作为加密查询字符串传递,例如https://example.com/somepage?id=AXYHNJK76PLOUY09YTTV4CDF,假设此处的 id 为 2,然后通过 $id = $_GET['id'] 获取它。

OR use Javascript to call an API that queries what you need.或使用 Javascript 调用 API 来查询您需要的内容。 DO NOT FORGET to put all security measures in place when using this method.使用此方法时,不要忘记采取所有安全措施。

IN YOUR CASE: run the query before before the HTML out put:在您的情况下:在 HTML 输出之前运行查询:

<?php
run query here
$queryResultId = your query that returns a result;
$encryptedId = encryptionfunction($queryResultId);
?>
<html>
<head>
</head>
<body>
<input type ="hidden" name="id_of_something" value="<?php echo 
$encryptedId; ?>" />
</body>
</html>

I don't know what the ID is for but remember you never expose an ID of a database to internet.我不知道 ID 的用途,但请记住,您永远不会将数据库的 ID 暴露给 Internet。 least you can do is encrypt it with Hash and Salt.至少你可以做的是用哈希和盐加密它。

将 php 文件作为后端(不要将其用作页面),在 html 中编写页面(可能使用一些 php 模板)然后从站点使用 js 调用函数,也不要连接非常不安全的查询),使用来自 mysqli 的绑定或最好使用 pdo。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM