Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取变量“quot;讯息;从链接中删除并使其在数据库中更新?_Php_Postback - Fatal编程技术网

Php 如何获取变量“quot;讯息;从链接中删除并使其在数据库中更新?

Php 如何获取变量“quot;讯息;从链接中删除并使其在数据库中更新?,php,postback,Php,Postback,嘿,所以我正在做一个网站,人们可以发送消息,我想把它放在我的数据库。但是他们可以更新信息。这是我正在使用的链接,但当访问它时,我收到此错误 0行已更新,已将hi添加到locker 这是一个错误,因为没有更新任何行 <?php define("MYSQL_HOST", "localhost"); define("MYSQL_PORT", "3306"); define("MYSQL_DB", "db"); define("MYSQL_TABLE", "table"); define("MY

嘿,所以我正在做一个网站,人们可以发送消息,我想把它放在我的数据库。但是他们可以更新信息。这是我正在使用的链接,但当访问它时,我收到此错误

0行已更新,已将hi添加到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参数传递某些数据属性。对于这个例子,该链接需要如下内容

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
的请求中有一个输入错误,应该是
引用

假设您的url是
www.google.com
,您希望从url参数传递某些数据属性。对于这个例子,该链接需要如下内容

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
的请求中有一个输入错误,应该在哪里
引用

$\u GET['message']将为您提供message的值我如何使用它并将其放入数据库@DhavalChheda$_GET['message']将为您提供message的值我如何使用它并将其放入数据库@达瓦切达