当我包含我的注释行时,不会显示任何结果

时间:2023-01-06 19:26:16

the code below works fine if I uncomment the commented lines, I'm really not sure as to why it is not displaying anything when I include the commented lines. Thank you for your time and assistance.

如果我取消注释注释行,下面的代码工作正常,我真的不确定为什么当我包含注释行时它没有显示任何内容。感谢您的时间和帮助。

I need that certain piece of code to check every time a phone number is searched so that it will automatically update the table "Notes" to Expired to let me know that the registration has already expired.

我需要在每次搜索电话号码时检查某段代码,以便它会自动将“Notes”表更新为Expired,以便让我知道注册已经过期。

<?php

include_once('assets/inc/db_login.inc');
session_start();

if($_SERVER["REQUEST_METHOD"] == "POST"){

if(empty($_POST["phone"])) {
  $unameErr = "Phone is required";
}
else {
  $phone = clean_input($_POST["phone"]);
}
}

$check = sql_entry($phone);

/* Functions */

function clean_input($login){

$login = trim($login);
$login = stripslashes($login);
$login = htmlspecialchars($login);

return $login;

}

function sql_entry($phone){

//do not touch anything beyond this part
$conn = mysqli_connect(DB_HOST,DB_USERNAME,DB_PASSWORD,DB_NAME);

//error catcher for connection failure
if($conn->connect_error){
  die("Connection failed: " . $conn->connect_error);
}

//clean themmmmmm!
$clean_phone = mysqli_real_escape_string($conn, $phone);

//prepare queries
$verification = "SELECT * FROM ".DB_TBL." WHERE phone = ".$clean_phone;
$verification_result = mysqli_query($conn,$verification); //run query to validate phone number

/*

$row = mysqli_fetch_array($verification_result, MYSQLI_ASSOC);

$startdate = $row['register_date'];
$expire = strtotime($startdate. ' + 182 days');
$today = strtotime("today midnight");

if($today >= $expire){
$update = "UPDATE ".DB_TBL." SET notes='Expired' WHERE phone = ".$clean_phone;
$run_update = mysqli_query($conn,$update);
}

*/

return $verification_result;
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> - | User Registration</title>

<link rel="stylesheet" type="text/css" href="styles.css" />

</head>

<body>
    <center><br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <table width="500", cellpadding=5 callspacing=5 border=1>
    <tr>
        <th>Name</th>
        <th>Register Date</th>
        <th>Phone</th>
        <th>Points</th>
        <th>Note</th>
    </tr>

    <?php while($rows = mysqli_fetch_array($check, MYSQLI_ASSOC)): ?>
        <tr>
            <td><?php echo $rows['username']; ?></td>
            <td><?php echo $rows['register_date']; ?></td>
            <td><?php echo $rows['phone']; ?></td>
            <td><?php echo $rows['points']; ?></td>
            <td><?php echo $rows['notes']; ?></td>
        </tr>
    <?php endwhile; ?>
    </table>
    </center>
</body>
</html>

2 个解决方案

#1


1  

You need to rewind result set so it could be iterated again or build data structure for both display and update with one iteration (actually you could update without pulling data from db - use conditions in query). Rewind would need less changes in the code - just add this at the end of commented part:

您需要回滚结果集以便可以再次迭代或者为一次迭代构建数据结构以进行显示和更新(实际上您可以在不从数据库中提取数据的情况下进行更新 - 在查询中使用条件)。倒带需要更少的代码更改 - 只需在注释部分的末尾添加:

mysqli_data_seek($verification_result, 0);

Btw. Your UPDATE works with first returned row only, and later you try to iterate like there could be more results. If it was the case then (without rewind) you would update first and display rest of them.

顺便说一句。您的UPDATE仅适用于第一个返回的行,稍后您尝试迭代,可能会有更多结果。如果是这种情况(没有倒带),您将首先更新并显示其余部分。

#2


0  

Add this line before the commented part:

在评论部分之前添加此行:

$verification_result_clone = clone($verification_result);

and replace

并替换

$row = mysqli_fetch_array($verification_result, MYSQLI_ASSOC);

with

$row = mysqli_fetch_array($verification_result_clone, MYSQLI_ASSOC);

UPDATE:

更新:

I didn't know that mysql_result class is not cloneable. Sorry for that.

我不知道mysql_result类是不可克隆的。对不起。

Well, I think you should run your query twice. Try this:

好吧,我认为你应该运行两次查询。尝试这个:

Replace

更换

$verification_result_clone = clone($verification_result);

with

$verification_result_clone = mysqli_query($conn,$verification);

from my answer above. That should work now.

从我上面的答案。那现在应该有效。

#1


1  

You need to rewind result set so it could be iterated again or build data structure for both display and update with one iteration (actually you could update without pulling data from db - use conditions in query). Rewind would need less changes in the code - just add this at the end of commented part:

您需要回滚结果集以便可以再次迭代或者为一次迭代构建数据结构以进行显示和更新(实际上您可以在不从数据库中提取数据的情况下进行更新 - 在查询中使用条件)。倒带需要更少的代码更改 - 只需在注释部分的末尾添加:

mysqli_data_seek($verification_result, 0);

Btw. Your UPDATE works with first returned row only, and later you try to iterate like there could be more results. If it was the case then (without rewind) you would update first and display rest of them.

顺便说一句。您的UPDATE仅适用于第一个返回的行,稍后您尝试迭代,可能会有更多结果。如果是这种情况(没有倒带),您将首先更新并显示其余部分。

#2


0  

Add this line before the commented part:

在评论部分之前添加此行:

$verification_result_clone = clone($verification_result);

and replace

并替换

$row = mysqli_fetch_array($verification_result, MYSQLI_ASSOC);

with

$row = mysqli_fetch_array($verification_result_clone, MYSQLI_ASSOC);

UPDATE:

更新:

I didn't know that mysql_result class is not cloneable. Sorry for that.

我不知道mysql_result类是不可克隆的。对不起。

Well, I think you should run your query twice. Try this:

好吧,我认为你应该运行两次查询。尝试这个:

Replace

更换

$verification_result_clone = clone($verification_result);

with

$verification_result_clone = mysqli_query($conn,$verification);

from my answer above. That should work now.

从我上面的答案。那现在应该有效。