0行更新,将其添加到储物柜。
,这是一个错误,因为没有更新行
<?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));
}
?>
答案 0 :(得分:0)
假设您有一个网址为www.google.com
,并且您想要从url参数传递某些数据属性。对于此示例,链接类似于以下内容。
www.google.com?color=blue
您可以执行以下操作从网址中检索值。
// 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
的请求中有一个拼写错误,其中应该是referral
。