0

好吧,这可能是我忽略的一些简单的事情,但我已经梳理了很多次..!

只需通过 PHP 表单进行简单更新,引入变量,构建查询:

// Connect
$connect = mysql_connect('host','login','passwd');
if (!$connect) { $errors .= "Not connected : ".mysql_error(); }
$database = mysql_select_db('db', $connect);
if (!$database) { $errors .= "Could not get to that database: ".mysql_error(); }

// Update database table
$info = "UPDATE `gsa_officers` SET `term` = '2012-2013', `office` = 'President', `type` = 'Poop', `dept` = 'Visual Arts', `name` = 'Matthew W. Jarvis', `email` = 'president@gsa.ucsd.edu', `blurb` = 'Serves as Chair of both the GSA Executive Committee and Council, oversees the direction of the organization and ensures the execution of its responsibilities and commitments.', `picture` = 'http://gsa.ucsd.edu/sites/gsa.ucsd.edu/files/mat%20w%20jarvis.jpg' WHERE `id` = 1";
$query = mysqli_query($info);
if (!$query) { $errors .= "Bad query: ".mysql_error(); }
mysql_close($connect);

我没有收到任何错误,它只打印出:“错误查询:”

我错过了什么/做错了什么?感谢任何额外的眼球^ _ ^

4

4 回答 4

1

mysql_connect()用于连接到数据库服务器并选择 db. 然后您使用mysqli_query()运行查询,然后mysql_error()报告错误。您不能混合使用这些 API。

您应该mysqli_*始终使用函数,因为这些mysql_*函数已被弃用,并且将从 PHP 的未来版本中删除。

例子:

// Connect
$mysqli = new mysqli('host','login','passwd','db');
if ($mysqli->connect_error) { $errors .= "Not connected : ".$mysqli->connect_error; }

// Update database table
$info = "UPDATE `gsa_officers` SET `term` = '2012-2013', `office` = 'President',
  `type` = 'Poop', `dept` = 'Visual Arts', `name` = 'Matthew W. Jarvis', 
  `email` = 'president@gsa.ucsd.edu', 
  `blurb` = 'Serves as Chair of both the GSA Executive Committee and Council, oversees the direction of the organization and ensures the execution of its responsibilities and commitments.',
  `picture` = 'http://gsa.ucsd.edu/sites/gsa.ucsd.edu/files/mat%20w%20jarvis.jpg' 
  WHERE `id` = 1";
if (!$mysqli->query($info)) {
    $errors .= "Bad query: ".$mysqli->error;
}
$mysqli->close();
于 2013-07-17T22:46:06.610 回答
0

更改此行

$query = mysqli_query($info);

$query = mysql_query($info);

笔记

mysql extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used.
于 2013-07-17T22:46:25.657 回答
0

您使用简单mysql(不是mysqli)连接但用于mysqli_query发送查询

于 2013-07-17T22:46:57.193 回答
0

如果你使用 mysql_query 而不是 mysqli_query 会怎样?

于 2013-07-17T22:47:23.163 回答