我如何从 link 中获取变量 "message" 并使其在数据库中更新?

How would I get the variable "message" from the link and make it update in the database?

嘿,所以我正在制作一个人们可以发送消息的站点,我想将其放入我的数据库中。但他们可以更新消息。这是 link 我正在使用 http://example.com/file.php?message=hi&referral=1 但在访问它时我收到此错误

0 Row updated, added hi to locker .

这是一个错误,因为没有更新任何行

<?php

define("MYSQL_HOST", "localhost");
define("MYSQL_PORT", "3306");
define("MYSQL_DB", "db");
define("MYSQL_TABLE", "table");
define("MYSQL_USER", "user");
define("MYSQL_PASS", "pass");
$mysqli = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
if ($mysqli->connect_errno) 
{
  echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$referral =            $_GET['refferal'];
$message =           $_GET['message'];

if (!($stmt = $mysqli->prepare("UPDATE ".MYSQL_DB.".".MYSQL_TABLE." SET message=(?) WHERE referral=(?) "))) 
{

  echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
$stmt->bind_param('ds', $message, $referral);
if (!$stmt->execute()) 
{
  echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
else
{
  printf("%d Row updated, added ".$message." to locker ".$referral." .\n", mysqli_stmt_affected_rows($stmt));
}
?>

假设您有一个 url 作为 www.google.com,并且您想从 url 参数传递某些数据属性。对于此示例,link 想要如下内容。

www.google.com?color=blue

您将执行以下操作以从 URL.

中检索值
// First lets define this variable so we do not get any undefined variable warnings in the error log.
$color = NULL; 

// second would be lets validate that this get parameter is set and not empty.
if ( !empty($_GET['color']) ) { 


 // We will then define the REQUEST to a variable for later calling.
    $color = $_REQUEST['color']; 
}

然后你可以简单地 echo $color 它的值将是 blue.

然后您可以简单地将您的 $color 变量应用到您的数据库语句。

最后,您的 refferal REQUEST 中有一个拼写错误,它应该是 referral