简体   繁体   中英

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 ...

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.

 $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. 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. 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'].

OR use Javascript to call an API that queries what you need. 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:

<?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. least you can do is encrypt it with Hash and Salt.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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